Convert foreign characters to HTML with PHP
I am trying to build a function to extract the Facebook ID of a user.
The simple part of my function works fine, but I would like to display the user's name as well - this breaks down when foreign characters are displayed.
You can see the test form here:
This is already populated with a foreign character Facebook ID.
I would like to find some way to globally switch this to HTML, in other words change this:
This would then cover every possible FB language... Spanish, Polish, Greek, Russian...
To go through all of the characters one at a time seems silly - like this:
$description = ereg_replace('\u0142','ł', $description);
Off hand I don't know an easy way to do this, though you could probably do something with preg_replace_callback(), using a character class that is a range of UTF-8 character codes above decimal 255. But my first thought is, why bother? Why not just serve up the page as UTF-8 and not worry about it?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
This works if there were some way to shorten it to a function... say, for X =...
$idurl = 'http://www.facebook.com/tkliwinihilisci';
$page = file_get_contents("https://graph.facebook.com/$idurl");
$string = $page;
$ent = array( // Convert Foreign Language Characters to HTML
$string = strtr("$string", $ent);
Last edited by donatello; 07-12-2011 at 05:20 AM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread