Today, URLs can contain Unicode characters. Which the code you linked to doesn’t handle. For example, encodeCharacter("个") returns “63”. The correct value is “%E4%B8%AA”, i.e. three encoded characters, not one.
And it’s a more work to encode a complete string then a single character.
A better alternative (if you insist on using AppleScript, that is
)would be the stringByAddingPercentEncodingWithAllowedCharacters method of the NSString class (or a similar method), which you can access through the ASObjC bridge. Still more than a single line of code, I guess, but at least you should get the correct result.