Remove †And Other Strange Variables in PHP?

I just created a feed reader and it has a tendency to pick up strange variables such as â€.

I’ve tried using the php str_replace to remove it but for some reason it does not.

Is there an easy operation to remove these?

A couple others:
œ

There is that strange box one too. How can I clean from strings/txt?

Thanks
Ryan

The “strange characters” are a result of getting bytes in one character-encoding and showing them in another. Try the iconv function or replacing the characters based on their ord() values. If you want to see my example code :google: “widgets.php Hack” for iconv() and “comment-template Hack” for ord()

You’ll need to convert feed content to your target charset (from utf-8) or convert your page to utf-8.

I tried this with no success:


utf8_encode($news['body'])

Would that work? Can I worry about converting the information once it is in my database?

Thanks
Ryan

since my page’s content is content=“text/html; charset=iso-8859-1”

I need to convert from whatever char to iso-8859-1, right?

I tried


iconv("UTF-8", "ISO-8859-1", $news['description'])

With no success.

So I guess my two questions are:

Is that conversion what I’m supposed to be doing? And, since it didn’t work on the echo, does it have to take place before database insertion?
Ryan

You’d be looking for http://php.net/utf8_decode on the feeds.

It may be because that the feeds contain characters outside of iso-8859-1’s range.

Yeah. I got it to work. I had to use iconv before adding the content to the database.

We’ll see how it goes.

Ryan

Props dude, just what I was looking for!