Convert a string to ascii

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Convert a string to ascii

Post 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!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Convert a string to ascii

Post 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
(#10850)
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Re: Convert a string to ascii

Post 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.
Post Reply