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://82l.net/l/426406613113802612.html">2015年山西特岗教师笔试什么是考试?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/125360984.html">日语句型&quot; ようとした ”是什么意思?举例说明</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/375056403.html">2012年国考行测真题及答案,可以免费下载的</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/570098501.html">身边感人的道德故事并从中悟出优秀品质 写一篇文章</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/79369539.html">联想家悦D2030E应该怎么升级可以换独立显卡吗·8600GT或者更高的显卡</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/558494895721788172.html">单招要会考成绩吗</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/2143200381403742908.html">怎样查询我的住房公积金个人账户</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/105108927.html">三国战记模115拟版的诸葛亮怎么都选不出来啊</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/152652201.html">六年级下册语文知识与能力训练</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://82l.net/l/758926592627247484.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://82l.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?098a6a07cd59ce2fcae0ccc02d6c5e96"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>