www.webdeveloper.com
Results 1 to 4 of 4

Thread: Special characters and php/xml/flash

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Question Special characters and php/xml/flash

    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?

    thx!

    -Z

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    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

    eBookworm.us

  3. #3
    Join Date
    Jun 2006
    Posts
    2
    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 ;"?

    thx!!

    -Z

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    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

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles