Jump to content

Output issues


jcruz

Recommended Posts

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
Share on other sites

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
Share on other sites

[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
Share on other sites

Nevermind, I resolved it. :D

It 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.