I am trying to get at the desired content in this tag:
<p class="address">
desired content
</p>
this is my attempt:
preg_match_all("/\<p class=\"address\">(.*)\<\/p\>/", $contents, $matches);
But the $matches array is empty. Please help.
Thanks
You could try this:
$contents = '<p class="address">desired content</p>';
$res = preg_match_all("/\<p class=\"address\">(.*)\<\/p\>/s", $contents, $matches);
var_dump($res);
var_dump($matches);
$matches is not empty, right?
.
also match \\n
- see modifiers .*?
(ungreedy operator) to not prevent matching </p>
in the capture group like so:
<?php
$contents = '<p class="address">
desired content
</p>';
$res = preg_match_all('#<p class="address">(.*?)</p>#s', $contents, $matches);
var_dump($matches);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.