html_entity_decode when reading from a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sebarry
    New Member
    • Jul 2007
    • 69

    html_entity_decode when reading from a database

    Hi,

    I'm trying to read the results of a database query into an XML document but it's only read so far and stopping. The XML document is as follows:

    [CODE=xml]
    <?xml version="1.0" encoding="utf-8"?>

    <night>

    <name>Poontan g</name>

    <homePageSummar y>Launches 26th November</homePageSummary >

    <whatsOnPageSum mary>Every Monday from 26th Nov Door price: £5/£4 Guestlist (07809867930)</whatsOnPageSumm ary

    >

    <description>Po ontang is of course, a punch made from the fermented juice from the rare poonberry bush

    . It became hugely popular during colonial times, it was a favourite of the Founding Fathers, drank constantly

    by George Washington, as evedenced by his farewell address, 'I only took the job for the poontang'.

    &lt;br /&gt;


    &lt;br /&gt;


    The first recorded recipe was printed in Ye Boston Globe. Unfortunately, poontang's immense popularity

    was later learned to be the result of addictive qualities. &lt;br /&gt;


    &lt;br /&gt;


    The hunger for good quality poontang is said to have made a Bishop kick a hole in a stained glass window

    . Withdrawl will occur, leading to unappealing physical &amp;amp; mental consequences, including blue

    balls, hairy palms &amp;amp; lack of mental clarity. &lt;br /&gt;


    &lt;br /&gt;


    COME SEE THE POONTANG PANDA.... &lt;br /&gt;


    Performing its erotic pole dance routine &lt;br /&gt;


    Pouring free poontang punch from the stage &lt;br /&gt;


    Giveaway baby poontang panda cuddly toys &lt;br /&gt;


    and if your lucky he might just hump your leg! &lt;br /&gt;


    &lt;br /&gt;


    DRINKS &lt;br /&gt;


    Baby Champers 70p! &lt;br /&gt;


    Bottles of Sol &amp;amp; Sambucca Shots &amp;pound;1 &lt;br /&gt;


    Double Spirit &amp;amp; Mixer inc Red Bull &amp;pound;2 .40 &lt;br /&gt;


    Poontang Pitchers &amp;amp; Red Pig Pithcers &amp;pound;5 &lt;br /&gt;


    Bottles of House Wine &amp;pound;7 &lt;br /&gt;


    &lt;br /&gt;


    MUSIC &lt;br /&gt;


    Big Panda Party Tunes -&amp;gt; Dance, R'n'B and Indie &lt;br /&gt;


    &lt;br /&gt;</description>

    <thumbnail>thum b447.jpg</thumbnail>

    <flyer>poon_fly er451.jpg</flyer>

    </night>
    [/CODE]

    I'm using the following the try and sort out the entities.

    [CODE=php]
    function html_numeric_en tities($str)
    {
    return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0") .chr(59)', $str);
    };

    $description = html_numeric_en tities(html_ent ity_decode($row['description']));
    $description = $night->appendChild($d om->createElement( 'description', $description));
    [/CODE]

    But it's only getting so far. I've tried it with just html_entity_dec ode but it gets struck with ampersands and £ signs. So I be using htmlentities when writing to the database, along with addslashes and then html_entity_dec ode when reading from the database. I've also had problems with hyphens. The PHP code can create the database but the Javascript code that reads the XML document when I'm creating an Ajax.Request cannot.

    Hopefully some kind soul can guide on what I'm doing wrong.

    Thanks,

    Sean
    Last edited by pbmods; Nov 26 '07, 04:07 PM. Reason: Fixed CODE tags.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Sean.

    Instead of worrying about HTML entities, try using CDATA tags.

    Comment

    Working...