I am using PHP to generate some XML. I need to put quotes in some of the text that is sent. I can use htmlentities or htmlspecialchars() to convert the quotes to special characters and the special characters display fine in Firefox or Chrome. However, in Internet Explorer it just creates a blank item.
In Firefox it writes:
<marker description="Yes "I Do"/>
In IE it writes:
<marker description=""\>
Here’s the pertinent code:
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
header("Content-type: text/xml");
$node = $dom->createElement("marker");
$newnode->setAttribute("description", htmlentities("Yes \"I Do"))
echo $dom->saveXML();
Sorry, I have been trying to debug everything and I posted the wrong text. I have been using htmlspecialchars() as the change notes it still does not work. I tried the " as a test and it works in Firefox but not IE. Sorry for the original typo. – user1098504 14 hours ago
As a test, put “Yes "I Do” in anyway, and see if IE is still broken. – SpikeX 14 hours ago
I have it working now. I had been trying the htmlspecialchars() and tried the " as a test. I think somewhere when I was testing I did not clear the cache every time with IE and even though I was doing a force refresh it was not always refreshing. I think part of my original problem was someone copied and pasted the original data into the form and ended up with angle quotes. Any ideas for converting these? Thanks for again for your help with my problem even though I think it was a refresh error.
You need to change this line:
To this:
You can use
htmlspecialchars()to achieve the same thing, if you don’t want to do each entity by hand.