I'm trying to use xpath to obtain xml node values that match a specific pattern (anything that has the pattern YYYY/MM/DD). In the example below, I would only want to find the 2nd item. I've tried using fn:matches and php:functionString with preg_match, to no avail.
<sometag>
<link>site:www.mysite.com/2014/</link>
</sometag>
<sometag>
<link>site:www.mysite.com/2014/01/07</link>
</sometag>
I thought I was on the right track here, but surprise surprise, it did not work.
$regex = '~(0[1-9]|1[012])[- /.](19|20)\d\d[- /.](0[1-9]|[12][0-9]|3[01])~';
$results = $xml->xpath("//link[php:functionString('preg_match', '".$regex."', .)]");
I've tried looking for just "2013" using fn:matches, this also didn't work.
$results = $xml->xpath("//link[fn:matches('2013')]");
What am I doing wrong?
DOMXPathonly supports XPath 1.0, for your second attempt, you can usecontainsinstead ofmatches