Page 1 of 1

Convert a string to ascii

Posted: Fri Aug 15, 2008 4:27 pm
by Parody
I am trying to send user inputted text from server to server and the most logical way to do it seems to be to convert the string being sent to a safe format containing only safe characters. After some research I think that ASCII would be the best as it only contains &,#,numbers and ; which won't disrupt anything (will it?).

Is there a function to convert a string to ascii and another to convert back or do I have to do a series of str_replace() for all of the ascii characters?

Thanks to anyone who helps me out!

Re: Convert a string to ascii

Posted: Fri Aug 15, 2008 5:02 pm
by Christopher
Look at the string functions in the manual. There are a number of functions that might help:

http://www.php.net/manual/en/ref.strings.php

Re: Convert a string to ascii

Posted: Sat Aug 16, 2008 3:38 am
by Parody
The only function which I think could be any use would be ord(), but that only provides a one way conversion and would require an extremely long loop to complete a whole string of text. Someone must have done this before, it seems like a pretty simple thing to do.