I am executing an external command in PHP via exec and I take that output (which is an array) and then get the individual strings search for specific strings. I then wish to echo those strings to the screen. However, some of these strings contains XML examples and they are getting stripped. How can I keep PHP from stripping the XML? I'm using PHP 5.6.2.
我正在通过exec在PHP中执行一个外部命令,并获取输出(即一个数组),然后获取对特定字符串的搜索。然后我希望将这些字符串回显到屏幕上。然而,其中一些字符串包含XML示例,它们正在被删除。如何避免PHP剥离XML?我使用PHP 5.6.2。
For example, I am trying to echo $val that has the following output:
例如,我正在尝试对具有以下输出的$val进行回送:
Missing test tag. Please add the test tag and set it to true. i.e. <data><test>true</test></data>.
But instead I am getting the following:
但我得到的却是以下信息:
Missing test tag. Please add the test tag and set it to true. i.e. true.
As you can see, the "data" and "test" xml tags are getting stripped.
正如您所看到的,“数据”和“测试”xml标记正在被删除。
1 个解决方案
#1
4
You could convert them to htmlentities
:
您可以将它们转换为htmlentities:
$str = 'Missing test tag. Please add the test tag and set it to true. i.e. <data><test>true</test></data>.';
echo htmlentities($str, ENT_XHTML);
#1
4
You could convert them to htmlentities
:
您可以将它们转换为htmlentities:
$str = 'Missing test tag. Please add the test tag and set it to true. i.e. <data><test>true</test></data>.';
echo htmlentities($str, ENT_XHTML);