Jump to content

[SOLVED] URL Decode...


gevans

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.