In XPath 1.0 (which is, I believe, the best you can get with PHP SimpleXML), you'd have to use the translate()
function to produce all-lowercase output from mixed-case input.
For convenience, I would wrap it in a function like this:
function findStopPointByName($xml, $query) {
$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ???"; // add any characters...
$lower = "abcdefghijklmnopqrstuvwxyz???"; // ...that are missing
$arg_stopname = "translate(StopName, '$upper', '$lower')";
$arg_query = "translate('$query', '$upper', '$lower')";
return $xml->xpath("//StopPoint[contains($arg_stopname, $arg_query)");
}
As a sanitizing measure I would either completely forbid or escape single quotes in $query
, because they will break your XPath string if they are ignored.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…