Jump to content

Recommended Posts

Is the resulting text from escape() in JavaScript identical to the textual result of urlencode() in php?

 

I'm sending a form using javascript to a php script. I want to encode the textarea so it's suitable for sending.

 

Most articles say it is fine, but the third post here: http://www.phpbuilder.com/board/showthread.php?t=10318476 says that it is not the same.

 

I've start using this piece of code;

 

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

 

Any views?

Link to comment
https://forums.phpfreaks.com/topic/175353-solved-url-decode/
Share on other sites

Sounds like an ajax thing.

But anyway escape() is certainly not the same as urlencode(). Why don't do a simple test containing the & character or send some text containing %20 or something like that.

See if something goes wrong on your serverside script.

 

Other then that using urlencode will only really matter if your planning to use the get method even you're using a post method instead you don't really have to bother with it.

Link to comment
https://forums.phpfreaks.com/topic/175353-solved-url-decode/#findComment-926039
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.