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. Link to comment https://forums.phpfreaks.com/topic/47571-solved-is-there-a-function-in-php/ 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)); } ?> Link to comment https://forums.phpfreaks.com/topic/47571-solved-is-there-a-function-in-php/#findComment-232274 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. Link to comment https://forums.phpfreaks.com/topic/47571-solved-is-there-a-function-in-php/#findComment-232290 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. Link to comment https://forums.phpfreaks.com/topic/47571-solved-is-there-a-function-in-php/#findComment-232297 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. Link to comment https://forums.phpfreaks.com/topic/47571-solved-is-there-a-function-in-php/#findComment-232304 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... Link to comment https://forums.phpfreaks.com/topic/47571-solved-is-there-a-function-in-php/#findComment-232317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.