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 (ie "myfunc", "MyFunc", "myFunc", etc.)?
match是XPath 2函数,在XPath 1中,您必须使用translate将其转换为规范化的大小写:
//*[@*[contains(translate(., "MYFUNC", "myfunc"),"myfunc")]]
Use the case-insentitive option for matches:
foreach($domxpath->query('//*[@*[matches(.,"myfunc","i")]]') as $node) {
To compare a sequence of values, just use =
to do a node set comparison:
(. = ("myfunc", "MyFunc", "myFunc"))
will return true if anything in the left sequence anything in the right sequence. From XPath spec :
If both objects to be compared are node-sets, then the comparison will be true if and only if there is a node in the first node-set and a node in the second node-set such that the result of performing the comparison on the string-values of the two nodes is true.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.