Apostrophe, XML and JS call escaping

  • Got an Apostrophe issue.
    My XML is generated via PHP and MySQL queries.

    I have the following to create the beginning scene tag......

    echo "<scene name=\"" . $index . "\" title=\"" . $name . "\" onstart=\"set(hotspot.enabled,true); js(myfunction(" . $name . ",$lat,$long)); ";

    My issue is that I have two uses of the variable $name; one that sets the "title" of the scene and one that is used in a JS call.
    When an apostrophe is used in the text associated with $name all heck breaks loose.
    Otherwise everything is perfect.

    I've tried escaping the variable $name in two formats; %27 for the JS call ( as one would for tooltips ) and ' for the XML "title".....

    1. $namejs = str_replace("'","%27",$name);
    2. $namexml = str_replace("'","'",$name);


    ....where $namejs is used for the JS call and $namexml is used to set the "title".


    This does not seem to work. Or I've missed something.

    The above method of str_replace() works just fine for escaping the text for tooltips:

    $tooltip1 = $row1['tooltip'];
    $tooltip = str_replace("'","%27",$tooltip1);

    Been fiddling with this for a bit now and am somewhat stumped. *confused*


    Any ideas?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!