citizen citizen - 2 months ago 9x
PHP Question

case insensitive search in xpath 1

I am searching through HTML for "myfunc". However, the capitalization is uncertain. Unfortunately, PHP works with XPath 1 so all searches are case-sensitive.

How can I update the following code to search for "myfunc", "MyFunc", "myFunc", etc.?

foreach($domxpath->query('//*[@*[contains(.,"myfunc")]]') as $node) {

The following doesn't work. Nor did my attempt at implementing a translate() work-around.

foreach($domxpath->query('//*[@*[matches(.,"[mM][yY][fF][uU][nN][cC]")]]') as $node) {

If regex is not possible, how could I search on an array of strings (i.e. "myfunc", "MyFunc", "myFunc", etc.)?


matches is a XPath 2 function, in XPath 1 you have to use translate to convert it to a normalized case:

 //*[@*[contains(translate(., "MYFUNC", "myfunc"),"myfunc")]]