I'm grabbing some tweets and printing them out on my site and curly apostrophes are being rendered as "â€tm". This is not good. What php function should I run the string through to get these weird characters to display as something closer to '?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Is there a way to play audio on a mobile browser w
str_replace('â€tm', "'", $dirty_string)
might give you a quick and dirty fix. But it seems to me like a character encoding problem. You may read the tweets using an encoding and displaying them in another encoding.You'd have to check your code and make sure you use the same encoding all over the place if you wanna do this the "clean way".
I battled with this for almost a day and then found that this function will work 100% of the time. It works with utf-8 and unicode and converts characters that are beyond the base ascii set into their html entities. It's good for cleaning up MS Word rubbish.
To convert to HTML entities:
See docs for mb_convert_encoding for more encoding options.
You could try to use the following function:
call:
this will change utf-8-chars into htmlentities, so you can display them in different encodings.
I was having trouble in Chrome with this.
Adding a
to the "head" section fixes it