我正在进行xpath搜索,我已经进行了搜索,但是我需要让它不区分大小写.我正在使用的xml文件是1.0,从我的研究意味着我必须使用一些称为翻译函数的东西,但我不确定如何做到这一点.
这是我的搜索文件:
$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>";
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助.
ala*_*inm 18
XPath 1.0:
$qry = "//channel/item[contains(
translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),
translate($search, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]"
Run Code Online (Sandbox Code Playgroud)
XPath 2.0:
$qry = "//channel/item[lower-case(.) = lower-case($search)]"
Run Code Online (Sandbox Code Playgroud)
两者都将小写字母替换为小写字母.