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] Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Define [i]not working[/i]. Quote Link to comment 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. =/ Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
jcruz Posted January 11, 2007 Author Share Posted January 11, 2007 Let me try that then! Quote Link to comment 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 :) Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 11, 2007 Share Posted January 11, 2007 Congrats. Quote Link to comment 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] 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.