Skip to content Skip to sidebar Skip to footer

Characters Being Rendered Strangely In Html/php

I'm presenting an RSS feed with this part of a PHP function: echo '
  • $item_title
  • '; Using an example, this o

    Solution 1:

    Choose you character encoding to match your what you are editing check this site to learn more. http://htmlpurifier.org/docs/enduser-utf8.html

    Solution 2:

    I took out the charset meta tag because I understood that it was bad practice for speed/SEO. When putting it back in, the problem is rectified, thank you. However, is there an alternative that is better practice? Setting headers via PHP - is that prefferable or worse?

    So your problem was that you were outputting text in some encoding, without informing the browser what encoding you're giving it, and the browser therefore misinterpreting the text in the wrong encoding, leading to garbage characters. You always need to inform clients about what encoding you're sending them text in. The primary method to do that over HTTP is an HTTP Content-Type header. That way the browser is informed about the type of content it receives before it actually receives the content. Which is exactly as it should be.

    HTML <meta> tags are only a fallback. You should include them, since they help specify the encoding of the HTML document should it ever be used outside of an HTTP context (e.g. you just open it from your hard disk, no HTTP involved, no HTTP Content-Type header, no way to specify the encoding... other than the HTML <meta> tag). But again, it should only be a fallback. And there's absolutely no issue with SEO or speed; wherever you got that from, it's pure FUD.

    Solution 3:

    This will work for you. first just use mb_convert_encoding() function it will wok for you.

    $item_title = addslashes('this is your text');
    
     $item_title = mb_convert_encoding($item_title, "HTML-ENTITIES", 'UTF-8');
    

    Post a Comment for "Characters Being Rendered Strangely In Html/php"