/    Sign up×
Community /Pin to ProfileBookmark

String Replace (Ampersand)

Hello everyone, I posted this Monday [URL=”http://www.webdeveloper.com/forum/showthread.php?t=227236&highlight=replace”]as a reply[/URL], but I didn’t get any help, so I am posting it as a new thread. I hope this is okay.

Basically, I am running an Ajax/PHP combo that uses PHP to make a MYSQL query and returns the results live in the search box. The problem is that all ampersands are being returned as HTML code. E.G. & returns & Is there a way to properly replace that code back to an ampersand?

Here is the javascript function that performs the retrieval of contents from PHP (PHP only returns text):

[CODE]//Called when the AJAX response is returned.
function handleSearchSuggest() {
if (searchReq.readyState == 4) {
var ss = document.getElementById(‘search_suggest’)
ss.innerHTML = ”;
var str = searchReq.responseText.split(“n”);
for(i=0; i < str.length – 1; i++) {
//Build our element string. This is cleaner using the DOM, but
//IE doesn’t support dynamically added attributes.

var suggest = ‘<div onmouseover=”javascript:suggestOver(this);” ‘;
suggest += ‘onmouseout=”javascript:suggestOut(this);” ‘;
suggest += ‘onclick=”javascript:setSearch(this.innerHTML);” ‘;
suggest += ‘class=”suggest_link”>’ + str[i] + ‘</div>’;
ss.innerHTML += suggest;
}
}
}[/CODE]

A working example of this issue can be found at: [url]http://www.financeglobe.com/SocialNet/Markets/[/url] and typing in abercrombie and then clicking on the suggestion.
Many thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Apr 17.2010 — You can do it server-side using [url=http://www.php.net/manual/en/function.html-entity-decode.php]html-entity-decode()[/url] or client-side.var str = searchReq.responseText.replace(/&amp;amp;/gi,"&amp;").split("n");
Copy linkTweet thisAlerts:
@iwpgauthorApr 19.2010 — Thank you Declan1991!
×

Success!

Help @iwpg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...