我将一个字符串保存到数据库中 然后我在php文件中以xml格式检索该数据,并从另一个php调用该xml数据 文件。它适用于存储在数据库中的简单文本记录,但是当我保存这样的字符串时 我替换<到& lt和> & gt然后保存到数据库
if x<y and y>z
并在php文件中检索它输出是一个xml结构 e.g
<questions><question><question_id>2</question_id>
<question>what is matrix</question><weight>6</weight>
<subject_code>4</subject_code></question>
<question><question_id>3</question_id><question>squareroot 3 is</question><weight>3</weight><subject_code>4</subject_code></question>
<question><question_id>15</question_id><question>what is a set</question><weight>4</weight><subject_code>4</subject_code></question><question><question_id>16</question_id>
<question>If x < y, y < z then</question><weight>4</weight><subject_code>4</subject_code></question></questions>
它显示我&amp; lt而不是'&lt;'在最后一个问题中(如果x&amp; lty和y&amp; ltz)
但是当我从另一个php文件中调用它时,它会给出错误
Warning: simplexml_load_string(): Entity: line 1: parser error : EntityRef: expecting ';' in /var/www/test/view/addTestQuestion.php
on line 54 Call Stack: 0.0007 332148 1. {main}() /var/www/test/view/addTestQuestion.php:0 0.0222 333892 2. simplexml_load_string()
/var/www/test/view/addTestQuestion.php:54 Warning: simplexml_load_string(): ubject_code>16If x /var/www/test/view/addTestQuestion.php:0 0.0222 333892 2. simplexml_load_string()
/var/www/test/view/addTestQuestion.php:54 Warning: simplexml_load_string(): ^
in /var/www/test/view/addTestQuestion.php on line 54 Call Stack: 0.0007 332148 1. {main}() /var/www/test/view/addTestQuestion.php:0 0.0222 333892 2. simplexml_load_string() /var/www/test/view/addTestQuestion.php:54 Warning: simplexml_load_string(): Entity: line 1: parser error : EntityRef: expecting ';' in
/var/www/test/view/addTestQuestion.php on line 54 Call Stack: 0.0007 332148 1. {main}() /var/www/test/view/addTestQuestion.php:0 0.0222 333892 2. simplexml_load_string() /var/www/test/view/addTestQuestion.php:54 Warning: simplexml_load_string(): de>16If x line 54 Call Stack: 0.0007 332148 1. {main}() /var/www/test/view/addTestQuestion.php:0 0.0222 333892 2. simplexml_load_string() /var/www/test/view/addTestQuestion.php:54 Warning: simplexml_load_string(): ^ in
/var/www/test/view/addTestQuestion.php on line 54 Call Stack: 0.0007 332148 1. {main}() /var/www/test/view/addTestQuestion.php:0 0.0222 333892 2. simplexml_load_string()
/var/www/test/view/addTestQuestion.php:54 Notice: Trying to get property of non-object in /var/www/test/view/addTestQuestion.php on line 56 Call Stack: 0.0007 332148 1. {main}
() /var/www/test/view/addTestQuestion.php:0 Warning: Invalid argument supplied for
foreach() in /var/www/test/view/addTestQuestion.php on line 56 Call Stack: 0.0007 332148 1. {main}() /var/www/test/view/addTestQuestion.php:0
任何帮助将不胜感激
答案 0 :(得分:3)
引用以&
开头,以;
结尾。你在任何地方都没有;
。
答案 1 :(得分:2)
您不能将<
或>
字符用作XML中的文字字符,请使用实体:
<question>If < y, y > z</question>
检索到该文本字符串后,您可以使用html_entity_decode
函数将其解码为真实的XML字符串。