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://85l.net/l/368501576653113684.html">我的世界手机版生存模式怎么挖钻石</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/717135049776338725.html">dreamweaver设计网页怎样实现页面内跳转到指定位置?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/622070168229548172.html">吃螃蟹不能吃什么水果</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/130358585.html">一个人不合群的原因是什么!</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/424120592359636812.html">光驱坏了,怎么用U盘装系统。请详细说一下,谢谢了。谢谢了,大神帮忙啊</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/243631474.html">BH - 105蓝牙耳机怎么换电池 ,能不能换?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/286373125.html">黑莓8830输入法和主题</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/510504145.html">快要结婚了为什么没有喜悦感觉</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1116883321234647219.html">发光字多少钱一平方?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://85l.net/l/1796243373134451107.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://85l.net/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?d7381e8e13750926596c531b05a19c89"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>