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://www.g230.com/460270816.html">汽车轮毂16寸换18寸有什么影响</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/431365502.html">我们家今天腌咸鸭蛋,腌好后是放在冰箱里吗?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/169962831.html">极品飞车10 无法使用1.4补丁</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/176783715.html">大学暑假寝室让住吗?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/372968948.html">白金口袋妖怪?电鬼如果要进化?得怎么弄啊?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/244558404036205324.html">我女朋友和我分手了,想挽回她怎么办。</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/1957764945096734420.html">迅雷是不是开通了会员下载速度能变快</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/1179918601983067899.html">王者荣耀阿轲怎么玩 王者荣耀阿珂技能玩法详细介绍</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/365543875303514652.html">我喜欢一个处女座的男生,可是他不喜欢我,以前我朋友喜欢他,刚开始</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://www.g230.com/1894613987917158060.html">交通事故赔偿纠纷,我是被告,开庭当日因为有事不能出庭,亲属代为出庭,委托书怎么写?</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://www.g230.com/static/old/img/fhtop.png" alt="返回顶部" 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?78733b427b0a9dce19688d903e89fc12"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>