In your question it looks like a typo, there is no function named ends-with therefore I would expect it not to work:
//tr[/td/a/img[php:function('ends-with',@id,'_imgProductImage')]
^^^^^^^^^
Instead use the right syntax, e.g. the correct function name:
//tr[/td/a/img[php:function('ends_with',@id,'_imgProductImage')]
^^^^^^^^^
Or for example like with the following example:
book.xml:
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<title>PHP Basics</title>
<author>Jim Smith</author>
<author>Jane Smith</author>
</book>
<book>
<title>PHP Secrets</title>
<author>Jenny Smythe</author>
</book>
<book>
<title>XML basics</title>
<author>Joe Black</author>
</book>
</books>
PHP:
<?php
$doc = new DOMDocument;
$doc->load('book.xml');
$xpath = new DOMXPath($doc);
// Register the php: namespace (required)
$xpath->registerNamespace("php", "http://php.net/xpath");
// Register PHP functions (no restrictions)
$xpath->registerPHPFunctions();
// Call substr function on the book title
$nodes = $xpath->query('//book[php:functionString("substr", title, 0, 3) = "PHP"]');
echo "Found {$nodes->length} books starting with 'PHP':\n";
foreach ($nodes as $node) {
$title = $node->getElementsByTagName("title")->item(0)->nodeValue;
$author = $node->getElementsByTagName("author")->item(0)->nodeValue;
echo "$title by $author\n";
}
As you can see, this example registers all PHP functions including the existing substr() function.
See DOMXPath::registerPHPFunctions for more information, that is also where the code example has been taken from.
I hope this is helpful, let me know if you still have a question about this.
See as well:
ends_withorends-with. There's a hyphen in function name_so it'sends_with'ends-with'inside your xpath to'ends_with'and you should be fine. I think that is what @gwillie wanted to say. At least I'd say that is the first thing one should try out as it seems to be the easy spot to fix this.