问题描述:

I have a string that is coming from a drupal text area. The string in drupal contains html tags but when I print the string I do not see them.

This string is later going into new SimpleXMLElement, but since it has some problematic characters, I want to call on it:

$string = htmlspecialchars($string, ENT_XML1 | ENT_QUOTES,'UTF-8', false);

The problem is that afterward, my string looks as follow

<?xml version="1.0" encoding="UTF-8"?>

<Data xmlns="http://www.digitalmeasures.com/schema/data" xmlns:dmd="http://www.digitalmeasures.com/schema/data-metadata" dmd:date="2016-11-03">

<Record userId="1" username="y" dmd:surveyId="1127463">

<dmd:IndexEntry indexKey="x" entryKey="x &amp; x" text="x &amp; Life x"/>

This is a small portion of the string

Thus, when I am calling SimpleXMLElementon it I am getting

String could not be parsed as XML

i tried to avoid this with the double_encode value set to false, but it is not working.

I cannot remove the SimpleXMLElementon step, it breaks some of the drupal's functionality.

What am I doing wrong?

____EDIT_____

as a check I replaced the htmlspecialchars with

$replace = str_replace('&', '&amp;', $string);

this is working fine.

网友答案:

$replace = str_replace('&', '&', $string);

相关阅读:
Top