i use PHP file to send data from my web to JS. And i sending data to php by URL. For xample. www.web.com/send.php?data=Hello everybody. And my problem is, if someone send special character or emoticon, PHP script wont work. Is there any function to encode string to string only with letters and numbers, and on PHP side decode it? Thanks, for replyes ;).
In javascript use:
encodeURIComponent('Hello everybody')
In PHP use:
$data=$_GET['data'];
In javascript you should use the following function to encode the url:
var url = 'www.web.com/send.php?data='+encodeURIComponent('Hello everybody');
in php you can use:
$data = $_GET['data'];
I'am using these functions for decode/encode
public function encode($string)
{
$string=$string*1498158+825920496;
return urlencode(base64_encode($string));
}
///////////////////////////////////////////////////////////////////////////////
public function decode($string)
{
$string=base64_decode(urldecode($string));
$string=($string-825920496)/1498158;
return $string;
}