URL encoder

By Daveoh on Jul 29, 2007

This is a custom identifier and command that will return text encoded to suit URLs (e.g. hello%20world)
Usage: $urlencode(text) will return the encoded text, and /urlencode text will echo the encoded text.
Do not enter the whole URL into the text, only the parameter values that need encoding.

alias urlencode {
  var %r = $regsubex($$1-,/([!#$%&'()*+,/:;=?@[] ])/g,% $+ $($base($asc(\t),10,16)))
  $iif($isid,return,echo -a) %r


Sign in to comment.
Daveoh   -  Jul 29, 2007

Oh hmm I definitely entered it as \t, since I copied and pasted my script, but I added the backslash in.
The closing bracket character is escaped, and the only one that needs to be (since $ for example cannot mean the end of a string in a character class.)
Also, not all non-alphanumeric characters should be encoded (even if that is an idea) since only these characters and alpha-num form a valid URI according to internet standards. Even more so, the characters -_.~ should not be encoded.

Olliegod   -  Jul 29, 2007

I don\'t see how it can work, there are quite a few errors with errors with the regex that I can see. $asc(t) would need to be changed to $asc(\t) and all of the []()/ etc. characters in the regex string should be prefixed with a \ so that they are interpreted as characters and not a closing bracket or something. Also there are special regex escape strings which would be much better for capturing all non alphanumeric characters.

Daveoh   -  Jul 29, 2007

Ok, -a is a good idea, but it sure works.
Maybe your mIRC ver., or other scripts.

Olliegod   -  Jul 29, 2007

Well 1. It didnt seem to work at all for me. //echo -a $urlencode(hmm testing;=!@#$%^&) returned: hmm testing;=!@#$%^&

And 2. If you do /urlencode 1 or any other number for that matter, it will give you an error. So I suggest you change the echo to echo -a.

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.