//This function takes text and converts it to valid
//url characters. This function does not do any
//security checks. In general you would only run user input
//through this function to pass along in a URL. Eg:
// return$ = "http://www.domain.com/index.php?var=" + url_encode(user_input$)
FUNCTION url_encode(string_to_encode AS STRING)
string_output AS STRING = ""
char_str AS STRING = ""
hex_code AS STRING = ""
FOR char = 1 TO LEN(string_to_encode)
char_str = MID$(string_to_encode,char)
ascii_code = ASC(char_str)
IF (ascii_code =< 32) OR (ascii_code => 159 AND ascii_code =< 191) OR (ascii_code => 159) OR (ascii_code => 34 AND ascii_code =< 38) OR ascii_code = 43 OR ascii_code = 44 OR ascii_code = 47 OR (ascii_code => 58 AND ascii_code =< 64) OR (ascii_code => 91 AND ascii_code =< 94) OR ascii_code = 96 OR (ascii_code => 123 AND ascii_code =< 126)
hex_code = RIGHT$(HEX$(ascii_code),2) //2 digits only!
string_output = string_output + "%" + hex_code
ELSE
string_output = string_output + char_str
ENDIF
NEXT char
ENDFUNCTION string_output