我正在尝试通过这样的 url(get 方法)传递阿拉伯语搜索词(用户单击缩略图):
<script>
function myClick2(clicked_id) {
window.location = clicked_id;
}
</script>
<div class ="image">
<a href="javascript:myClick2('./test.php?SearchWord=خوخ')">
<img src="http://awebsite.com/Thumb0.jpg" alt=".." />
<figcaption><a href="javascript:myClick2('./test.php?SearchWord=خوخ')">خوخ </a> <br /></figcaption>
</a>
</div>
用户单击主页上的缩略图后,调用如下所示:
http://mywebsite.com/test.php?SearchWord=خوخ
但我没有从脚本中得到任何输出,我得到的只是:string(0) ""
谁能告诉我为什么我的脚本没有输出以搜索词 خوخ 开头的数据集?
<?php
$str = <<<'STR'
تفاحة:
<br><img src="http://asite.com/1.jpg"><br>
<a href="https://asite.com/1.html">تفاحة</a> <br />
<a href="http://asite.com/link.html">link1 </a> <br />
<a href="http://asite.com/link.html">link2 </a> <br />
<a href="http://asite.com/link.html">link3 </a> <br />
<a href="http://asite.com/link.html">link4 </a> <br />
<a href="http://asite.com/link.html">link5 </a> <br />
--------------------------------------<br>
Mango:
<br><img src="http://asite.com/1.jpg"><br>
<a href="https://asite.com/Mango.html">Mango</a> <br />
<a href="http://asite.com/linkMango.html">link1Mango </a> <br />
<a href="http://asite.com/linkMango.html">link2Mango </a> <br />
<a href="http://asite.com/linkMango.html">link3Mango </a> <br />
<a href="http://asite.com/linkMango.html">link4Mango </a> <br />
<a href="http://asite.com/linkMango.html">link5Mango </a> <br />
--------------------------------------<br>
خوخ:
<br><img src="http://asite.com/1.jpg"><br>
<a href="https://asite.com/1.html">خوخ</a> <br />
<a href="http://asite.com/linkpeach.html">link1خوخ </a> <br />
<a href="http://asite.com/linkpeach.html">link2خوخ </a> <br />
<a href="http://asite.com/linkpeach.html">link3خوخ </a> <br />
<a href="http://asite.com/linkpeach.html">link4خوخ </a> <br />
<a href="http://asite.com/linkpeach.html">link5خوخ </a> <br />
--------------------------------------<br>
STR;
$start = $_GET["SearchWord"];
$end = '--------------------------------------<br>';
function get_string_between($string, $start, $end) {
// make sure we escape all parts of the pattern
$start = preg_quote($start, '/');
$end= preg_quote($end, '/');
// create the pattern
$pattern = "/$start(.*?)$end/su"; // using s and u pattern modifiers
if (preg_match($pattern, $string, $match)) {
return $match[1];
}
}
echo "<pre>";
var_dump(htmlspecialchars(get_string_between($str, $start, $end)));
echo "<pre>";
?>