I am trying to pass Arabic search term via url (get method ) like this(user clicks thumbnail image):
<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>
The call looks like this after user clicks thumbnail on main page:
http://mywebsite.com/test.php?SearchWord=خوخ
but i get no output from the script and all i get is :string(0) ""
Could any one tell me why my script doesn't output the set of data that starts with search word خوخ ?
<?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>";
?>
PHP has a function called iconv
You will want to encode any Arabic to ISO-8859-6 using iconv.
Encode it before passing it into a URL (when they click search) and then decode it within your controller/form function.