I have a variable $html
in which this code is stored
<form action="track_mobile.asp" method="post" name="TrackMobile">
<table width="99%" height="55" border="0" cellpadding="2" cellspacing="0">
<tr>
<td class="Heading2" colspan="2"> Track Any Mobile Location</td>
</tr>
<tr>
<td width="21" valign="top" rowspan="2" class="s2stextbox" valign="top"><img src="../images/operators_logo/Tata.png" width="134" height="121" align="left"> </td>
<td width="897" valign="top" class="s2stextbox"><font size="2"><b>Mobile Number: </b>918888888888</font></td>
</tr>
<tr>
<td width="897" valign="top" class="s2stextbox" valign="top"><font size="2"> <b>User Name:</b> We are unable to trace the Name for this Mobile Number<br>
<font size="2"><b>Mobile Operator Name:</b> TATA TELESERVICES<br>
<b>State/Region: </b>Maharashtra</font></td>
</tr> </table>
</form>
In which every item after ":(semicollon)" are random which comes different every time.
Plz give me correct syntax to get echo as
Mobile Number: 918888888888
User Name: We are unable to trace the Name for this Mobile Number
Mobile Operator Name: IDEA
State/Region: Maharashtra
in which these are ramdomly generated, different evey time so, that preg_match search this loaction and echo the text which are there in same loaction
918888888888
We are unable to trace the Name for this Mobile Number
IDEA
Maharashtra
$text = strip_tags($html);
I just change the regexp and display each value match by (.*)
(everything that follow the pattern up to the end of line:
preg_match('/Mobile Number: (.*)/', $html, $matches);
echo $matches[1];
preg_match('/User Name: (.*)/', $html, $matches);
echo $matches[1];
preg_match('/Mobile Operator Name: (.*)/', $html, $matches);
echo $matches[1];
preg_match('/State/Region: (.*)/', $html, $matches);
echo $matches[1];
This is a work for XPath
(see [SimpleXMLElement::xpath
][1], your XPaths look like be:
/form/table/tr[1]/td[2]/font[substring-after(./text(), ':') ->
/form/table/tr[2]/td[1]/font[1][substring-after(./text(), ':')
/form/table/tr[2]/td[1]/font[2][substring-before(substring-after(./text(), ':'), 'State')
/form/table/tr[2]/td[1]/font[2][substring-after(./text(), 'Region')