php正则表达式如何匹配title?

2024-11-23 01:11:29
推荐回答(3个)
回答1:

php正则表达式匹配title的代码如下:

$file = "百度知道——提问问题";

preg_match_all('/(.*)<\/title>/i',$file,$content); </p> <p>echo '<pre>';</p> <p>print_r($content);</p> <p>结果:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2Fb64543a98226cffc743c05d4be014a90f603ea46%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/b64543a98226cffc743c05d4be014a90f603ea46"></p></p> </div> </div> <div class="clear"></div> </div> <div class="wdhdnr"> <div class="huidanrtop"> <div class="wdhuidaxinx"> <div class="wdhuidaxm">回答2:</div> </div> </div> <div class="clear"></div> <div class="wdhuidanrmid"> <div class="zuijiacont"> <p><?php<br>$s = '<a title="abc.jpg" href="fefefe"><br> <img src="xsdsd.jpg" alt=\'xxsd.jpg\' title="eeerrfff" /><br> </a><br> <img src="xsdsd.jpg" alt="eeerrfff.pngxxsd" title="xxsd.jpg" />';<br>$pat = '/(<img.*?)((alt|title)=[\'"]+[^\'|"]*\.(jpg|gif|png|bmp)[\'"]+)/';<br>echo preg_replace($pat , '$1' , $s);<p><br></p> <p><br></p> <p></p></p> </div> </div> <div class="clear"></div> </div> <div class="wdhdnr"> <div class="huidanrtop"> <div class="wdhuidaxinx"> <div class="wdhuidaxm">回答3:</div> </div> </div> <div class="clear"></div> <div class="wdhuidanrmid"> <div class="zuijiacont"> <p><p>$file = "<title>百度知道——提问问题";

preg_match_all('/(.*)<\/title>/i',$file,$content); </p> <p>echo '<pre>';</p> <p>print_r($content);</p> <p>结果:</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F5ab5c9ea15ce36d3deabff853ff33a87e850b1d3%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/5ab5c9ea15ce36d3deabff853ff33a87e850b1d3"></p></p> </div> </div> <div class="clear"></div> </div> </div> </div> <div class="wendaright"> <div class="wdluluerwema"> <div class="wdxgwttop">相关问答</div> <div class="wdxgwtnr"> </div> <div class="clear"></div> </div> <!-- 其他随机问答['id'=>alphaID($like['zid'])] --> <div class="wdluluerwema"> <div class="wdxgwttop">最新问答</div> <div class="wdxgwtnr"> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/401581855.html">石家庄金戈大厦游泳馆怎么样啊?比全民健身中心呢?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/1673470060054007787.html">教师资格证面试初中可以报考哪些科目</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/336254251.html">英语现在完成时与过去完成时区分</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/45698832.html">《魔兽世界》的一些小问题!</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/1239581900291123419.html">张嘉译演的公安局长是林荫这部电视剧叫什么名</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/622288252252906132.html">黑龙江卫视前几天放的那个讲奉春公安局长的连续剧叫什么名字?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/651566388473493405.html">上面一个林下面一个土是什么字?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/118102493.html">感情烦恼,怎么办?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/243740726.html">世纪佳缘学历怎么改</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://191i.com/i/1436267131088599099.html">4点05和4点050的大小相等,计数单位不同。是错还是对?</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://191i.com/static/old/img/fhtop.png" title="返回顶部"></a></div> <div class="dibu"> <div class="dibu"> </div> </div> <div class="banquan"> <p>内容全部来源于网络收集,如有侵权,请联系网站删除:QQ:24596024</p> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?530214f19d678452e8fa4098a936ce38"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>