此问题已在此处找到答案:
如何使用php检查xml中是否存在标记((3个答案)
php domdocument获取节点值,其中属性值为(3个答案)
4小时前关门了。
我试图提取一个特定的html标记,如果它存在于给定的文本中。例如,在本文中:
<p><iframe loading="lazy" style="border: 1px solid #CCC; border-width: 1px; margin-bottom: 5px; max-width: 100%;" src="//www.slideshare.net/slideshow/embed_code/key/lnoOgCXrjl9I1X" width="595" height="485" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen="allowfullscreen"> </iframe></p><div style="margin-bottom: 5px;"><strong> <a title="Improving Civic Discourse on Facebook, Facebook's Civic Engagement Team" href="//www.slideshare.net/mysociety/improving-civic-discourse-on-facebook-facebooks-civic-engagement-team" target="_blank" rel="noopener noreferrer">Improving Civic Discourse on Facebook, Facebook’s Civic Engagement Team</a> </strong> from <strong><a href="https://www.slideshare.net/mysociety" target="_blank" rel="noopener noreferrer">mysociety</a></strong></div> <a class="twitter-timeline" data-width="900" data-height="1000" data-dnt="true" href="https://twitter.com/samidh" data-tweet-limit="5">Tweets by </a> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> <div id="jp-relatedposts" class="jp-relatedposts"><h3 class="jp-relatedposts-headline"><em>Related</em></h3></div>
我想检查标记是否存在,如果存在,则提取它。结果应该是:
<iframe loading="lazy" style="border: 1px solid #CCC; border-width: 1px; margin-bottom: 5px; max-width: 100%;" src="//www.slideshare.net/slideshow/embed_code/key/lnoOgCXrjl9I1X" width="595" height="485" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen="allowfullscreen"> </iframe>
i、 e iframe内容,包括标记(…)。我该怎么做呢?
1条答案
按热度按时间z8dt9xmd1#
您可以使用
DOMDocument
类,使用javascript查询dom,并可能检查属性。