Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果存在';s小于符号后没有空格_Php_Xml - Fatal编程技术网

Php 如果存在';s小于符号后没有空格

Php 如果存在';s小于符号后没有空格,php,xml,Php,Xml,当我试图显示从XML文件中提取的小于和大于符号中包含的一些文本时,我注意到一种奇怪的行为 请尝试以下示例: $xml = '<doc> <one>&lt;&lt;Hello&gt;&gt; "Hello" inside less than and greater than symbols will not be printed</one> <two>&lt;&lt; Hello&

当我试图显示从XML文件中提取的小于和大于符号中包含的一些文本时,我注意到一种奇怪的行为

请尝试以下示例:

$xml = '<doc>
    <one>&lt;&lt;Hello&gt;&gt; "Hello" inside less than and greater than symbols will not be printed</one>
    <two>&lt;&lt; Hello&gt;&gt; "Hello" is printed because there is a space after "&lt;" </two>
</doc>';

$simple = simplexml_load_string($xml);

echo "<pre>";
    print_r($simple);
echo "</pre>";

echo "This works fine: &lt;&lt;Hello&gt;&gt;";
$xml='1!'
Hello“Hello”内的小于和大于符号将不会被打印
Hello“Hello”已打印,因为“”后面有空格
';
$simple=simplexml\u load\u字符串($xml);
回声“;
打印(简单);
回声“;
echo“这很好用:你好”;
正如您可能注意到的,如果小于符号后没有空格,则不显示文本,只显示一个小于和一个大于符号

问题是,我正在处理的XML文件恰好在小于和大于符号之间包含了一些文本,小于符号后没有任何空格。顺便说一句,如果您在浏览器中查看源代码(Ctrl-U),文本将正确显示:

simplexmlement对象
(
[one]=>“Hello”内的小于和大于符号将不会被打印

[two]=>>“Hello”被打印是因为“之后有一个空格,但它不会显示在浏览器中,因为它会将其解释为html标记。您需要为您打印的所有节点转义html字符。

代码工作正常:。这是浏览器,请参阅Alex的答案
<pre>SimpleXMLElement Object
(
    [one] => <<Hello>> "Hello" inside less than and greater than symbols will not be printed
    [two] => << Hello>> "Hello" is printed because there is a space after "<" 
)
</pre>
This works fine: &lt;&lt;Hello&gt;&gt;