douliangli6407 2013-09-04 17:01
浏览 14
已采纳

preg_match_all()使用

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">&nbsp;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
  • 写回答

2条回答 默认 最新

  • duan111112 2013-09-04 18:19
    关注

    1. Strip-out HTML tag

    $text = strip_tags($html);
    

    2. Match using text before column

    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];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂