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
Used Versions
PHP 8.2, Laminas MVC 3.2, Symfony 5.2, Laravel 8.28, PHPUnit 9.5, Doctrine ORM 2.8