I am stucked into some problem
Here is my code
<?php
$code='$var';
$phone='$var1';
$default='0';
$html = file_get_contents('http://www.phunwa.com/phone/0191/2604122');
$name = preg_replace('/(.*)(<p><strong>Name:<\/strong> )([^<]+)(<\/p>)(.*)/mis','$3',$html);
$myVar = isset($name)?$name:$default;
$address = preg_replace('/(.*)(<p><strong>Address:<\/strong> )([^<]+)(<\/p>)(.*)/mis','$3',$html);
$location = preg_replace('/(.*)(<p><strong>Location:<\/strong> )([^<]+)(<\/p>)(.*)/mis','$3',$html);
$othernumbers = preg_replace('/(.*)(<p><strong>Other Numbers:<\/strong> )(.*)/mis','$3',$html);
list($othernumbers,$trash)= preg_split('/<\/p>/mis',$othernumbers,0);
if ($myVar ==0){echo 'Not Found'; }
else{echo 'name: '.$myVar.'<br>address: '.$address.'<br>location: '.$location.'<br>other numbers: '.$othernumbers;
}
exit;
?>
I am trying to ftech the website Data . The code is working with out if statement if the phoen number exist . if the phone number dosent exist the original website says "NOT FOUND" . But my code is not handeled if number dosent exist .
The below is the tag in the source website shows when the number is not found.
<h1 class="second-page-title">Not found: 00191 - 2530152</h1>
I tried to make some default value . My code fails for not found condition . In the above code the number is valid and exit and it will echo the results if "if" statement is removed. if you give nay random number. it will show "Not Found. Please help me sort this out. Thanks
NEW EDIT
The problem is I am not able to find out the way in which if I can assign variable $name as 0 if it did not return the desired value. Although it always turn 1 in for myVAR. :(
After long wait of reply from all PHP gurus . On temporary basis I have used if ( strtoupper($name)==$name) statement since fortunatly all the $name are capital letters .Its not a permanent solution but its working as per now.
I am still waiting for expert advice.
use if ($myVar =='0'){echo 'Not Found'; }
also better syntax is $myVar = (isset($name)) ? $name : $default;