Drezard Posted June 10, 2007 Share Posted June 10, 2007 Okay I'm trying to write a PHP Script to that splits a string up then uses a switch statement to change the characters into numbers. So far thats all I got. But, it doesn't work for some reason. It works and doesn't display any errors but it doesn't give the output I wanted. Heres the script: <?php if (!isset($_POST['submit'])) { echo "* are required fields <br /> <br /> Form: <br /> <br /> <form method='POST'> *String <input type='text' name='string'> <br /> <input type='submit' name='submit'> </form> <br />"; } if (isset($_POST['submit'])) { $string = mysql_escape_string($_POST['string']); $arr = str_split($string); $arrsize = count($arr); for ($int = 0; $int > $arrsize; $int++) { switch ($arr[$int]) { case 'a': $char = 1; break; case 'b': $char = 2; break; case 'c': $char = 3; break; case 'd': $char = 4; break; case 'e': $char = 5; break; case 'f': $char = 6; break; case 'g': $char = 7; break; case 'h': $char = 8; break; case 'i': $char = 9; break; case 'j': $char = 10; break; case 'k': $char = 11; break; case 'l': $char = 12; break; case 'm': $char = 13; break; case 'n': $char = 14; break; case 'o': $char = 15; break; case 'p': $char = 16; break; case 'q': $char = 17; break; case 'r': $char = 18; break; case 's': $char = 19; break; case 't': $char = 20; break; case 'u': $char = 21; break; case 'v': $char = 22; break; case 'w': $char = 23; break; case 'x': $char = 24; break; case 'y': $char = 25; break; case 'z': $char = 26; break; case ' '; $char = 27; break; echo $char . "<br>"; } } } ?> It should do something like this: Input: drezard Output: d r e z a r d Whats wrong with this script? Regards, Daniel Link to comment https://forums.phpfreaks.com/topic/54953-problem-with-encryption-script/ Share on other sites More sharing options...
paul2463 Posted June 10, 2007 Share Posted June 10, 2007 I have jst tried running it and I get a Fatal error: Call to undefined function: str_split() in C:\Program Files\xampp\htdocs\phptest\string.php on line 21 according to the manual it only runs in PHP5 which I dont have so I had to geta function to help me, your problem is that the echo $char . "<br>"; is one curly brace too high it should be case 'y': $char = 25; break; case 'z': $char = 26; break; case ' '; $char = 27; break; } echo $char . "<br>"; } hello comes out as 8 5 12 12 15 Link to comment https://forums.phpfreaks.com/topic/54953-problem-with-encryption-script/#findComment-271762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.