如何使Xpath搜索不区分大小写 [英] How do i make Xpath search case insensitive
本文介绍了如何使Xpath搜索不区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在进行xpath搜索,搜索已经开始工作,但是我需要使其不区分大小写.我正在使用的xml文件是1.0,根据我的研究,这意味着我必须使用某种称为转换功能"的东西,但是我不确定如何执行此操作.
I'm currently making a xpath search, I've got the the search working but I need to make it case insensitive. The xml file I'm using is 1.0 which from my research means I've got to use some thing called a translate function but I'm unsure of how to do this.
这是我的搜索文件:
$holidayDoc = simplexml_load_file('holidays.xml');
// fetch data from form
$txtSearch = $_GET['txtSearch'];
$qry = "//channel/item[contains(.,\"$txtSearch\")]";
$holidays = $holidayDoc->xpath($qry); // do the xpath query
// now loop through all the students
echo "Showing title search results for $txtSearch";
foreach ($holidays as $holiday)
{
echo "<p><a href=\"{$holiday->link}\">{$holiday->title}</a></p>
<p><small>$holiday->pubDate</small></p>";
任何帮助将不胜感激.
推荐答案
XPath 1.0:
XPath 1.0 :
$qry = "//channel/item[contains(
translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),
translate($search, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]"
XPath 2.0:
XPath 2.0 :
$qry = "//channel/item[lower-case(.) = lower-case($search)]"
将所有大写字母都替换为小写字母.
Both replace all upper case to lower case.
这篇关于如何使Xpath搜索不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文