2015-12-04 211 views
2

我想要获取一个可变的所有孩子节点的内容。例如:删除所有的孩子节点,并获取simpleXML的内容

<p><distinct type="twitter-retweet"><ident>RT</ident> 
      <addressingTerm><addressMarker>@</addressMarker><addressee type="twitter-account" 
       ref="https://twitter.com/LePG 35022597" 
      >LePG</addressee></addressingTerm>:</distinct> A 07h50, 
       <addressingTerm><addressMarker>@</addressMarker><addressee type="twitter-account" 
       ref="#cmr-politweets-p80820758">JLMelenchon</addressee></addressingTerm> est 
      l'invité des #4vérités sur <distinct type="twitter-hashtag"><ident>#</ident><rs 
       ref="https://twitter.com/search?q=%23France2&amp;src=hash" 
      >France2</rs></distinct>. Nous live-tweeterons. #Chômage <distinct 
      type="twitter-hashtag"><ident>#</ident><rs 
       ref="https://twitter.com/search?q=%23Municipales2014&amp;src=hash" 
       >Municipales2014</rs></distinct></p> 

我想在输出有这样一句话:

“RT @LePG一个07h50,@JLMelenchon L'EST德邀请#4vérités河畔#France2奴斯活tweeterons。 #Chomage#Municipale2014“

问题是当我使用asXML(),我也有变量中的节点。

感谢

回答

0

虽然它看起来有点警察出来的,如果你不被迫使用SimpleXML和可以获取XML作为字符串:我想建议简单地使用“用strip_tags” http://us3.php.net/manual/en/function.strip-tags.php

否则,你需要递归地解析孩子来构建字符串。如有必要,我将使用递归函数进行更新。