2015-12-04 140 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

否則,你需要遞歸地解析孩子來構建字符串。如有必要,我將使用遞歸函數進行更新。