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 ;).
2
-
If you use a form, that is done automatically. How / where is your url generated?jeroen– jeroen2014-12-23 16:13:16 +00:00Commented Dec 23, 2014 at 16:13
-
1javascript encodeURIComponent and PHP urlencodeCollett89– Collett892014-12-23 16:14:45 +00:00Commented Dec 23, 2014 at 16:14
Add a comment
|
3 Answers
In javascript use:
encodeURIComponent('Hello everybody')
In PHP use:
$data=$_GET['data'];
1 Comment
Evert
The contents of the
$_GET superglobal are already percent-decoded.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;
}