1

我正在尝试通过这样的 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>";

?>
4

1 回答 1

0

PHP有一个叫做iconv的函数

您需要使用 iconv将任何阿拉伯语编码为ISO-8859-6 。

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

于 2016-08-18T19:51:36.683 回答