Hi,
First time poster! hope this isnt too newbie...
I'm trying to use the code here: http://developers.evrsoft.com/docs/p...entities.shtml
in order to convert text to the ASCII code necessary to display it in Flash. The problem is that it uses letter-based special character codes, like ˜, rather than something like "& # 8 2 1 2 ;" (spaces added so you can see it in the browser), and its not reading in flash. Is there a similar function which converts special characters to number-based instead of letter-based ascii code?
I played around with some things and came up with this little script, from which you should be able to use the functions to accomplish your needs:
PHP Code:
<?php
header("Content-Type: text/plain");
function convert_entity($entity)
{
return(sprintf("&#%d;", ord(html_entity_decode($entity))));
}
function html_numeric_entities($text)
{
$text = htmlentities($text);
$text = preg_replace('/(&\w+;)/e', "convert_entity('\\1')", $text);
return($text);
}
# Try it out:
$test = 'This <b>is</b> a "test".';
$result = html_numeric_entities($test);
echo "BEFORE:\n$test\n\n";
echo "AFTER:\n$result\n\n";
echo "BACK TO ORIGINAL:\n".html_entity_decode($result);
?>
"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
Wow thanks NogDog! I'll give that a try. So the final result of this script would be numeric value, eg rather than "& a m p ; " it would be "& # 3 8 ;"?
Yes. Just add the two function definitions to your script, then call the html_numeric_entities() function, specifying the initial (unencoded) string that you want converted.
"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
Bookmarks