如何通过url传递阿拉伯字符串(GET方法)正确地找到使用php的子字符串


How to pass Arabic string via url (GET method) properly to find substring using php?

我试图通过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'
&#1578;&#1601;&#1575;&#1581;&#1577;:
<br><img src="http://asite.com/1.jpg"><br>
<a href="https://asite.com/1.html">&#1578;&#1601;&#1575;&#1581;&#1577;</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>
&#1582;&#1608;&#1582;:
<br><img src="http://asite.com/1.jpg"><br>
<a href="https://asite.com/1.html">&#1582;&#1608;&#1582;</a> <br />
<a href="http://asite.com/linkpeach.html">link1&#1582;&#1608;&#1582; </a> <br />
<a href="http://asite.com/linkpeach.html">link2&#1582;&#1608;&#1582; </a> <br />
<a href="http://asite.com/linkpeach.html">link3&#1582;&#1608;&#1582; </a> <br />
<a href="http://asite.com/linkpeach.html">link4&#1582;&#1608;&#1582; </a> <br />
<a href="http://asite.com/linkpeach.html">link5&#1582;&#1608;&#1582; </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>";
?>

PHP有一个函数叫做iconv

使用iconv.

将任何阿拉伯语编码为ISO-8859-6

在将其传递到URL(当他们点击搜索时)之前对其进行编码,然后在控制器/表单函数中解码