[英]Get value of 'p' tag using preg_match in PHP
I can get value within tag 'p' using below PHP code 我可以使用下面的PHP代码在标签“ p”中获取值
$pattern ='/<p>(.*)<\/p>/';
$str = '<div class="sample"><p>Hi welcome</p></div>';
preg_match($pattern, $str, $matches);
print_R($matches);
But I've another HTML code which've more space after tag break tag. 但是我还有另一个HTML代码,其中在break break标签之后有更多空间。 Here is my code. 这是我的代码。
<div class="boxes-box-content"><p>Call: (+61 3) 8639 9000<br />
<a href="mailto:info@rgit.edu.au">info@rgit.edu.au</a><br />
28-32 Elizabeth Street, Melbourne<br />
VIC 3000, Australia</p>
</div>
In above code, there is more space after break tag. 在上面的代码中,break标记后有更多空间。 So I can't get the value of tag 'p'. 因此,我无法获取标签“ p”的值。 Is any other method to get value of 'p' tag. 是获取“ p”标签值的任何其他方法。
I want to get results as 我想得到结果
Call: (+61 3) 8639 9000 致电:(+61 3)8639 9000
info@rgit.edu.au info@rgit.edu.au
28-32 Elizabeth Street, Melbourne 墨尔本伊丽莎白街28-32号
VIC 3000, Australia 澳大利亚VIC 3000
Best way to parse HTML is by using PHP DOM Class . 解析HTML的最佳方法是使用PHP DOM Class 。 Though if you still want to use preg_match in this can use below regex (added ) and check, 虽然如果您仍要使用preg_match,则可以在正则表达式下面(添加)进行检查,
$pattern = "/<p>(.*)<\/p>/s";
Woking DEMO . 沃克演示 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.