ballhogjoni Posted April 18, 2007 Share Posted April 18, 2007 Is there a function in php that will decode this to regular characters? so instead of this: \074\141\040\150\162\145\146\075\042$l1dt\042\076\074\142\076 It would be this: <a href="$l1dt"><b> I use the ascii table, and decode it by hand, but i want to write a program that will do it automatically. Quote Link to comment Share on other sites More sharing options...
Lumio Posted April 18, 2007 Share Posted April 18, 2007 All of the characters are a little invalid... because I get the following string: J(–¢‘’K*$l1dt*LJŽL Doing this code: <?php $str = '\\074\\141\\040\\150\\162\\145\\146\\075\\042$l1dt\\042\\076\\074\\142\\076'; echo preg_replace_callback('/(\\\\[\d]{3})/', "replaceChar", $str); function replaceChar($arr) { return chr(substr($arr[1], 1)); } ?> Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 18, 2007 Author Share Posted April 18, 2007 none of the characters are invalid. if you use the ascii table they are correct. Quote Link to comment Share on other sites More sharing options...
mpharo Posted April 18, 2007 Share Posted April 18, 2007 this what your lookin for? chr (PHP 4, PHP 5) chr — Return a specific character Description string chr ( int $ascii ) Returns a one-character string containing the character specified by ascii. Example 2306. chr() example <?php $str = "The string ends in escape: "; $str .= chr(27); /* add an escape character at the end of $str */ /* Often this is more useful */ $str = sprintf("The string ends in escape: %c", 27); ?> You can find an ASCII-table over here: » http://www.asciitable.com. This function complements ord(). See also sprintf() with a format string of %c. Quote Link to comment Share on other sites More sharing options...
ballhogjoni Posted April 18, 2007 Author Share Posted April 18, 2007 basically I want to be able to plug octal code like this: "\074\141\040\150\162\145\146\075\042$l1dt\042\076\074\142\076" into a form, and then I want to the form to output the transalation. Quote Link to comment Share on other sites More sharing options...
mpharo Posted April 18, 2007 Share Posted April 18, 2007 Then this function will do that, you will just need to feed it the results one by one with a loop... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.