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://o15.net/937747135074762412.html">描写重庆火锅的好段</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/304237981419997004.html">刚开的淘宝店怎么上货</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/1238424909179525619.html">梦幻西游带永不磨损的装备开运掉持久不?成功与否都掉5点?掉了之后还会在使用中掉不?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/1452642327197010020.html">时间的本质是什么?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/284327102.html">急!用iphone,装了QQ阅读,然后想通过“同步助手”来导入TXT小说,怎么弄?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/1670081764834746307.html">2015年贵州高考总分和高考状元多少分</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/552991604180692692.html">求一部电视剧,古装刑侦类的</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/1767629440052172740.html">能拍星空的手机都有哪些</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/333131851.html">想上中央戏剧学院、北京电影学院的非表演系专业,都要参加艺考么?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://o15.net/420287849.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://o15.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?f3a9e88f5de712f94fca1c4003dfb2e7"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>