wheat 发表于 2018-12-12 09:43:44

php函数simplexml_load_string转xml的小坑

  1、如下代码报错:

  

  php调试错误提示:Warning: simplexml_load_string(): Entity: line 1: parser error : StartTag: invalid element name in C:\wamp64\www1\test1.php on line 4
  2、后来重新书写了xml数据,调试通过,返回值成功

  

  3、注意加入LIBXML_NOCDATA参数后的区别,结果如下:
  var_dump($obj)如下:

  C:\wamp64\www1\test1.php:20:
object(SimpleXMLElement)
public 'ToUserName' => string '
toUser
' (length=12)
public 'FromUserName' => string '
fromUser
' (length=14)
public 'CreateTime' => string '1348831860' (length=10)
public 'MsgType' => string '
text
' (length=10)
public 'Content' => string '
this is a test
' (length=20)
public 'MsgId' => string '1234567890123456' (length=16)


var_dump($obj1)如下:
  C:\wamp64\www1\test1.php:22:
object(SimpleXMLElement)
public 'ToUserName' =>
object(SimpleXMLElement)
public 'FromUserName' =>
object(SimpleXMLElement)
public 'CreateTime' => string '1348831860' (length=10)
public 'MsgType' =>
object(SimpleXMLElement)
public 'Content' =>
object(SimpleXMLElement)
public 'MsgId' => string '1234567890123456' (length=16)




页: [1]
查看完整版本: php函数simplexml_load_string转xml的小坑