Log in

View Full Version : Replacing   and ° in PHP



brent.fraser
01-13-2009, 06:20 PM
Hi everyone.

It has been some time since I have done any coding (perl) and I am running into a bit of a headache. I am using some PHP and JS I downloaded from your site (http://www.dynamicdrive.com/dynamicindex17/rsspausescroller/) and I am putting a weather RRS feed on a web-page I am creating. The RSS is working as I am getting the information into my HTML browser but it is having   and ° in the output and not a space and degree symbol. I know from my long past days of perl that you can replace those with spaces and characters. I am still looking around the net for answers currently.... I looked into the PHP script and I think I have identified the place for the replacement of the values when outputting it into javascript:


// -------------------------------------------------------------------
// outputRSS_JS()- Outputs the "title", "link", "description", and "pubDate" elements of an RSS

feed in XML format
// -------------------------------------------------------------------

function outputRSS_JS($url, $divid) {
global $rss;
if ($rs = $rss->get($url)){
echo "rsscontentdata.$divid=new Array();\n";
$i=0;
foreach ($rs['items'] as $item) {
echo "rsscontentdata.$divid" . "[$i]={link:\"" . slashit($item[link]) . "\",

title:\"" . slashit($item[title]) . "\", description:\"" . slashit($item[description]) . "\",

date:\"" . slashit($item[pubDate]) . "\"}\n";
$i++;
}
if ($rs['items_count'] <= 0) { echo "rsscontentdata=\"Sorry, no items found in the RSS

file\""; }
}
else {
echo "rsscontentdata=\"Sorry: It's not possible to reach RSS file $url\"";
// All else fails
}
}

function slashit($what){ //Encode text for storing in JavaScript array
$newstring=str_replace('&apos;', '\'', $what);//replace those half valid apostrophe entities with actual apostrophes
return rawurlencode($newstring);
}
I have tried to change
$newstring=str_replace('&apos;', '\'', $what); to
$newstring=str_replace('&nbsp;', ' ', $what); and that isn't working in the output as I still see "&nbsp".

Any suggestions on how to replace the "&nbsp;" and "&deg;" in the PHP script?

Thanks for the patience.....