加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 使用SimpleXMLElement 获取元素内部文本

发布时间:2020-12-13 22:09:39 所属栏目:PHP教程 来源:网络整理
导读:参见英文答案 Accessing certain properties of a SimpleXMLElement Object????????????????????????????????????1个 我试图访问xml元素的文本值.我正在使用SimpleXMLElement.我必须遗漏一些明显的东西. h:html xmlns:jr="http://openrosa.org/javarosa" xml
参见英文答案 > Accessing certain properties of a SimpleXMLElement Object????????????????????????????????????1个
我试图访问xml元素的文本值.我正在使用SimpleXMLElement.我必须遗漏一些明显的东西.

<h:html xmlns:jr="http://openrosa.org/javarosa" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/2002/xforms">
  <h:head>
    <h:title>NewForm</h:title>      
  </h:head>
</h:html>

$xml = new SimpleXMLElement($resp);
$xml->registerXPathNamespace('h','http://www.w3.org/1999/xhtml'); 
// I have tried with and without the namespace (it doesn't seem to make a difference)

$result = $xml->xpath('//h:title');
debug($result);

运行上面的代码给了我:

array (
  0 => 
  SimpleXMLElement::__set_state(array(
     0 => 'NewForm',)),)

看起来很简单.我很难获得’NewForm’的价值

我试过了

$result [0],$result [0] – > {0},$result [0] [0].

迭代$result的子项[0].

有人可以帮助指导我正确的方向,以便我可以从标题元素获取文本?

解决方法

这对我的例子很有用:

echo (string)$result[0];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读