php - How to select the right div by class with Xpath? -


$divs = $xpathsuj->query("//div[@class='txt-msg  text-enrichi-forum ']"); $div = $divs[$i]; 

with xpath command i'm able select div class "txt-msg text-enrichi-forum " :

<div class="bloc-contenu">     <div class="txt-msg  text-enrichi-forum ">         <p>tu pourrais &eacute;crire en francais si ce n'est pas trop demand&eacute;?               <img src="http://image.jeuxvideo.com/smileys_img/54.gif" alt=":coeur:" data-code=":coeur:" title=":coeur:" width="21" height="20" />          </p>     </div> </div> 

but not 1 :

<div class="bloc-contenu">     <div class="txt-msg  text-enrichi-forum ">         <p>              <img src="http://image.jeuxvideo.com/smileys_img/42.gif" alt=":salut:" data-code=":salut:" title=":salut:" width="46" height="41" />         </p>     </div>     <div class="signature-msg  text-enrichi-forum ">         <p>break;</p>     </div> </div> 

what doing wrong?

i've tried both segments of xml , seems work both, there possibility there issue spacing.

in xpath query, looking exact match of 'txt-msg text-enrichi-forum ' has 2 spaces after txt-msg , 1 after last part. if spaces missing, not find element.

if change to...

$divs = $xpathsuj->query("//div[contains(@class,'txt-msg') , contains(@class,'text-enrichi-forum')]"); foreach ( $divs $div )   {     echo $doc->savexml($div).php_eol; } 

it should bit more tolerant.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -