Extend your XPath queries with PHP functions

Code
<?php

$file 
__DIR__ '/test.xml';

$dom = new DOMDocument('1.0');
$dom->load($file);

$xpath = new DOMXPath($dom);

// regular xpath expression
$title $xpath->query('/catalog/book[4]/title');
echo 
$title->item(0)->nodeValue PHP_EOL;

// register a php function
$xpath->registerNamespace("php""http://php.net/xpath");
$xpath->registerPHPFunctions(['strlen']);

// use php function in xpath expression
$title $xpath->query('/catalog/book[php:functionString("strlen", title) = "15"]/title');
echo 
$title->item(0)->nodeValue PHP_EOL;
Result
Oberon's Legacy
Maeve Ascendant