3

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? Commented Dec 23, 2014 at 16:13
  • 1
    javascript encodeURIComponent and PHP urlencode Commented Dec 23, 2014 at 16:14

3 Answers 3

1

In javascript use:

encodeURIComponent('Hello everybody')

In PHP use:

$data=$_GET['data'];
Sign up to request clarification or add additional context in comments.

1 Comment

The contents of the $_GET superglobal are already percent-decoded.
0

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'];

Comments

0

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;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.