tags:

views:

662

answers:

4

this is what i have right now

Drawing an RSS feed into the php, the raw xml from the rss feed reads:

Paul’s Confidence

The php that i have so far is this.

$newtitle = $item->title;
$newtitle = utf8_decode($newtitle);

The above returns;

Paul?s Confidence

If i remove the utf_decode, i get this

Paul’s Confidence

When i try a str_replace;

$newtitle = str_replace("”", "", $newtitle);

It doesnt work, i get;

Paul’s Confidence

Any thoughts?

+1  A: 

Try this:

$newtitle = html_entity_decode($newtitle, ENT_QUOTES, "UTF-8")

If this is not the solution browse this page http://us2.php.net/manual/en/function.html-entity-decode.php

czuk
A: 

Is the character encoding setting for your PHP server something other than UTF-8? If so, is there a reason or could it be changed to UTF-8? Though we don't store data in UTF-8 in our database, I've found that setting the webserver's character set to UTF-8 seems to help resolve character set issues.

I'd be interested in hearing others' opinions about this... whether I'm setting myself up for problems by setting webserver to UTF-8 while storing submitted data in Latin1 in our mysql database. I know there was a reason I chose Latin1 for the database but can't recall what it was. Interestingly, our current setup seems to allow for non-UTF-8 character entry and subsequent rendering... it seems that storing in Latin1 doesn't prevent subsequent decoding and display of all UTF-8 characters?

codemonkey
A: 

Read up on http://us.php.net/manual/en/function.html-entity-decode.php

That & symbol is a html code so you can easily decode it.

A: 

I solved the problem. Seems to be a short fix rather than the larger issue, but it works.

$newtitle = str_replace('’', "'", $newtitle);

I also found this useful snippit that may help others with same problem;

<?
$find[] = '“'; // left side double smart quote
$find[] = '”'; // right side double smart quote
$find[] = '‘'; // left side single smart quote
$find[] = '’'; // right side single smart quote
$find[] = '…'; // elipsis
$find[] = '—'; // em dash
$find[] = '–'; // en dash

$replace[] = '"';
$replace[] = '"';
$replace[] = "'";
$replace[] = "'";
$replace[] = "...";
$replace[] = "-";
$replace[] = "-";

$text = str_replace($find, $replace, $text);
?>

Thanks everyone for your time and consideration.

Patrick
This fails to work for a Linux box however as the 'php' file's encoding could be different rendering the special characters useless. Just an FYI.
Jakub