我正在尝试从a href获取标题。
我的代码返回带有内部文本的所有a href字符串。
<h2 class="post-title entry-title">
<a href="www.anewdomain.com">I want to get this title</a>
</h2>
preg_match_all("/<h2 class='post-title entry-title'>(.*?)<\/h2>/s", $result1, $matches1, PREG_OFFSET_CAPTURE);
$my_title =$matches1[1][0][0];
echo $my_title;
谢谢你们!!!
preg_match_all("/<h2 class='post-title entry-title'>(.*?)<\/h2>/s", $result1, $matches1, PREG_OFFSET_CAPTURE);
$my_title =strip_tags($matches1[1][0][0]);
echo $my_title;
它可能会解决您的问题。.正如您提到的,$matches1[1][0][0]
返回整个锚标签,因此将其剥离.. !!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句