jcruz Posted January 11, 2007 Share Posted January 11, 2007 Hello, everyone. I'm quite new to PHP; I'm mostly acquainted with Java.I wrote an application in Java that could change the base the characters in a string to bases 2-104 and that would output the string. After many, many headaches, I ported some of it to PHP. However, this code segment is not working for some odd reason. I have error reporting enabled in both PHP and Apache, yet I get no errors.Any help would be greatly appreciated!This is the code segment that is giving me trouble:[code]elseif ($_POST['Encode']){$input = $_POST['dectxt'];$output = "";for($counter = 0;$counter < (strlen($input));$counter++){ $temp = ord(substr($input,$counter,1)); if($temp > 255) { $output = "Invalid character detected."; break; } $temp2 = $marray[($POST_['base'])-2][temp]; $output = $output.$temp2;}echo "<form action='index.php' method='POST'>Text:<br><textarea cols='40' rows='10' wrap='virtual' name='dectxt'>" . $input . "</textarea><br>Base:<br><input type='text' size='3' value='" . $_POST['base'] . "' name='base'><br><input type='submit' value='Encode' name='Encode'><br>Text:<br><textarea cols='40' rows='10' wrap='virtual' name='enctxt'>" . $output . "</textarea><br><input type='submit' value='Decode' name='Decode'>";}[/code] Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/ Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 What is "not working"? What is the "trouble"?JINX Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157890 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Define [i]not working[/i]. Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157891 Share on other sites More sharing options...
jcruz Posted January 11, 2007 Author Share Posted January 11, 2007 ;D Sorry.Not working? Hmm, well, the text in the 'dectext' textarea is not getting processed by the upper code and displayed as correct output. In other words, it displays nothing. =/ Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157892 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 Where is $marray defined?Did you try print_r($_POST) to make sure all your expected vars are set?You can also try printing test at several points to see where the script is going. Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157902 Share on other sites More sharing options...
jcruz Posted January 11, 2007 Author Share Posted January 11, 2007 I'd post $marray here, but it's over 2,000 lines long. ;)print_r($_POST)? What exactly does this do? (Pardon my ignorance!)Edit: $marray is a 2-dimensional array that has 104 elements downward and each element has 256 characters corresponding to ASCII values 0-255. Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157904 Share on other sites More sharing options...
Cagecrawler Posted January 11, 2007 Share Posted January 11, 2007 print_r displays information about a variable. For example, if you use print_r($_POST), it'll display all of the array variables currently set and show their values. Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157908 Share on other sites More sharing options...
jcruz Posted January 11, 2007 Author Share Posted January 11, 2007 Let me try that then! Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157911 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 you can always type php.net/(function) to get info on a function you don't know about :) Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157915 Share on other sites More sharing options...
jcruz Posted January 11, 2007 Author Share Posted January 11, 2007 [quote author=jesirose link=topic=121877.msg501904#msg501904 date=1168483537]you can always type php.net/(function) to get info on a function you don't know about :)[/quote]Oh? Hmm, thanks for the advice! :)I tried print_r, and all the variables were correctly displayed. =/[code]Array ( [dectxt] => H [base] => 2 [Encode] => Encode [enctxt] => D )[/code]Also, I noticed that in the $marray[][temp], a $ was missing. I added it, but still no dice. Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157916 Share on other sites More sharing options...
jcruz Posted January 11, 2007 Author Share Posted January 11, 2007 Nevermind, I resolved it. :DIt seems you can't put too much stuff within brackets ([]), so I declared a temporary variable which housed "$_POST['base'] - 2" and put it in the brackets.I can't believe it works! It's completely backward compatible with my Java program. /drool Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157934 Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 Congrats. Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157939 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 This line....[code=php:0]$temp2 = $marray[($POST_['base'])-2][temp];[/code]should be....[code=php:0]$temp2 = $marray[($_POST['base'])-2]['temp']];[/code] Link to comment https://forums.phpfreaks.com/topic/33686-output-issues/#findComment-157940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.