PHP DOMXPath query to return value -


i want , show title, tel, fax , address if exist.

html code :

<div id="id1">        <div class="ab">         <ul>           <li class="title"> agence x </li>            <li class="tel"> 060000000</li>           <li class="fax"> 06000000</li>                  <li class="address> address </li>          </ul>        </div>       <div class="ab">   //the same class name      <ul>          <li class="titre"> agence x </li>            <li class="tel"> 060000000</li>             <li class="fax"> 06000000</li>        </ul>      </div>        <div>...</div>       </div>

i wrote code didn't know how write condition "if node class name 'address' or 'fax' or 'tel' exist' x.

here code:

$doc = new domdocument();  @$doc->loadhtmlfile('http://website.com');    $node = $doc->getelementsbytagname('div') ;  $xpath=new domxpath($doc);  $titre=$xpath->query('//div/ul/li[@class="titre"]');  $adresse=$xpath->query('//div/ul/li[@class="adresse"]');  $phone=$xpath->query('//div/ul/li[@class="phone"]');  $fax=$xpath->query('//div/ul/li[@class="fax"]');    $a=0;$b=0;$c=0;    for($i=0;$i<$titre->length;$i++)  {  	echo $titre->item($i)->nodevalue.'<br/>' ;       if(a "li" has classe="adresse" existe)      { for($a=0;$a<$adresse->length;$a++)      	       {     				echo $adresse->item($a)->nodevalue.'<br/>' ;     				$a++;     		 	}     		}    if(a "li" has classe="titre" existe){  for($b=0;$b<$phone->length;$b++)     	   {    			echo $titre->item($b)->nodevalue.'<br/>' ;    			$b++;    		}    }   if(a "li" has classe="fax" existe) { for($c=0;$c<$fax->length;$c++)     	     {   			echo $fax->item($c)->nodevalue.'<br/>' ;   			$c++;   	    }    	}        }

could tell me how can write condition or solution?


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -