Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php td的预赛_Php_Preg Match - Fatal编程技术网

Php td的预赛

Php td的预赛,php,preg-match,Php,Preg Match,我试图从td内部的网页中过滤数据,它是这样的: <td colspan="2">several anchor,bold and other html tags are inside this td</td> 此td中有几个锚定、粗体和其他html标记 我使用过这个preg_匹配,但它给出了所有其他td的输出,但在上面的例子中,它没有给出任何输出 preg_match("/\<td colspan\=\"2\"\>(.*)\<\/td\

我试图从td内部的网页中过滤数据,它是这样的:

    <td colspan="2">several anchor,bold and other html tags are inside this td</td>
此td中有几个锚定、粗体和其他html标记
我使用过这个preg_匹配,但它给出了所有其他td的输出,但在上面的例子中,它没有给出任何输出

    preg_match("/\<td colspan\=\"2\"\>(.*)\<\/td\>/",$str,$title);
preg\u匹配(“/\(.*)\/”,$str,$title);
以下是完整的td:

    <td colspan="2">
      <div align="left" style="width:370; height:315;">
            <ins style="display:inline-table;border:none;height:280px;margin:0;padding:0;position:relative;visibility:visible;width:336px">      

          <ins style="display:block;border:none;height:280px;margin:0;padding:0;position:relative;visibility:visible;width:336px" id="aswift_1_anchor"><iframe width="336" scrolling="no" height="280" frameborder="0" style="left:0;position:absolute;top:0;" name="aswift_1" id="aswift_1" onload="var i=this.id,s=window.google_iframe_oncopy,H=s&amp;&amp;s.handlers,h=H&amp;&amp;H[i],w=this.contentWindow,d;try{d=w.document}catch(e){}if(h&amp;&amp;d&amp;&amp;(!d.body||!d.body.firstChild)){if(h.call){setTimeout(h,0)}else if(h.match){w.location.replace(h)}}" allowtransparency="true" hspace="0" vspace="0" marginheight="0" marginwidth="0"></iframe></ins></ins>
           </div><p>  When starting out sometimes it is a good idea to write down your            <a href="#" style="text-decoration: underline !important;position:static;font-family:inherit !important;font-weight:inherit !important;font-size:inherit !important;" class="kLink" id="KonaLink1">   
      <font color="blue" style="color: blue !important; font-family:inherit !important;font-weight:inherit !important;font-size:inherit !important;position:static;">                   <span style="color: blue !impor  If you seriously want to take back control of your money you need to build a <a href="http://ezinearticles.com/?To-Set-Up-a-Personal-Budget-Get-a-Pencil-and-Paper&amp;id=1629478">Personal Budget</a>. To learn more about creating a budget please visit the website <a href="http://household-budget.home-choices-net.com">Household Budgets by clicking here</a>. </p><p> </p><p><!-- google_ad_section_end -->

              </p><p>
        <font style="color:02679D; font-size:12"><b><font color="000000">Related Articles - 

       </font>
           </b></font>
        </p><p><table width="100%" border="0"><tbody><tr>
        <td align="center">
           <br><br><br><br>

        <br><br>

          </font></p></td></tr></tbody></table>
            </p></td>

有时候在开始时,写下你的想法是个好主意。要了解有关创建预算的更多信息,请访问网站

有关条文—








通常不要使用正则表达式解析html。然而,您的问题是正则表达式非常强大,可以捕获所有可能的数据。尝试添加问号:

preg_match("/\<td colspan\=\"2\"\>(.*?)\<\/td\>/",$str,$title);
preg\u match(“/\(.*?\/”,$str,$title);
问号使组变为非gready,字符串将在下一个可能的标记处结束。

您需要添加修饰符:

如果设置了此修改器,则图案中的点元字符将匹配所有字符,包括换行符。如果没有它,新行就没有了 排除。此修饰符相当于Perl的/s修饰符。A. 像[^a]这样的负类总是匹配换行符, 与此修改器的设置无关


您知道使用regexps解析HTML是错误的吗?(好吧,至少有争议(除非你真的知道你在做什么))尝试([^我正在尝试匹配这个,我在匹配前使用了这个,但没有工作(“/\(.*)\/”,$str,$title);
        preg_match("/\<td colspan\=\"2\"\>(.*)\<\/td\>/s",$str,$title);
 s (PCRE_DOTALL)