开发者

Formatting problems when fetching feeds

开发者 https://www.devze.com 2022-12-18 07:24 出处:网络
When I fetch data from a feed I store it in a table, the problem is that the format of the quote, so It will store ’ instead of \' (I hope you can see the difference)

When I fetch data from a feed I store it in a table, the problem is that the format of the quote, so It will store instead of ' (I hope you can see the difference)

You get the same thing when you copy paste code from a website or word document in your editor.

the problem is that when I display the content on my site I开发者_如何学运维 get the following, how to I get rid of that?

Formatting problems when fetching feeds


The problem relates to character sets. You need to find out what the character set of the feed is (how it's encoded) and also how your site is encoded too.

If the feed will never contain HTML markup then you can use htmlentities() otherwise you'll need to do conversion of the feed at input so that it matches up with the same charset as your site.

MySQL has good internationalization support too and would be able to perform this conversion.

Without knowning the specifics of your site it's hard to advise further


Echo the text like this on your page:

echo  htmlentities($your_text_here);


James C already has the correct answer.

If your site is ISO-8859-1 encoded, and you are using the results of a UTF-8 encoded feed. In that case, a

utf8_decode($text);

would be a quick trick to make it work. On the long run, it would be good to switch to UTF-8 altogether.

If you're outputting data from your database, you need to check the encoding of your

  • database tables
  • the mySQL connection
  • your page encoding

For more sophisticated character set conversion, there is iconv().

Excellent basic reading on the issue is The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

0

精彩评论

暂无评论...
验证码 换一张
取 消