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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改