Reputation: 4003
Right now I have a xpath search function that looks like this:
$paragraph = $xmldoc->xpath("//p[contains(., '$wordsearch')]");
I was wondering if it is possible to let $wordsearch
be a regular expression, so that my search looked something like this:
$paragraph = $xmldoc->xpath("//p[contains(., '$regularExpression')]");
Thanks for your help.
Upvotes: 0
Views: 1058
Reputation: 197842
You can filter the array with the regex instead:
$paragraph = array_filter(
$xmldoc->xpath("//p"),
function ($p) use ($regularExpression) {
return preg_match($regularExpression, $p);
}
);
See array_filter
.
Upvotes: 1