PDA

View Full Version : PHP / MYSQL / XML question.



alistz
11-24-2008, 12:47 PM
This is a problem I'm stuck on:

I have a column in a mysql table that is an XML string.

When I create the record for the column I use htmlentities() so my user can add quotes when he types input into the heading.

looks like this :

$holdcolumn = '<message><head>htmlentities($head)</head><replies></replies></messsage>;

All is good, until I want to add a reply. When I Select the column from my table I place the result in an XML object. I then I update the <replies></replies> using $xml->replies->addChild('reply',"$replykey")

I then convert the xml to a string: $xmltext = $xml->asXML() so i can update the record

When I update the record's column in mysql I get an error because the quotes are back in the $xmltext and affecting the SQL string.

I"m not sure how to handle this, it seems like there should be a simple answer?

pghcollectibles
11-25-2008, 06:20 AM
depending on your exact syntax (slashes etc.) stripslashes() (http://us3.php.net/manual/en/function.stripslashes.php) removes quotes but there are other possible functions you may choose to use as well: str_replace() and even explode() could work depending on exactly what you're doing. look at the list of string functions and see what works best for your situation.