newbtophp Posted August 17, 2009 Share Posted August 17, 2009 What am I doing wrong?, im trying to create a script using the strtr function. Except the number dont work. <form action="index.php" method='post'> <p> Code<br /> <textarea name='code' rows="8" cols="50"></textarea><br> Number<br /> <input type="text" name="number" /><br /> strtrfrom<br /> <input name="strtrfrom" value="" size="50" type="text" /><br /> strtrtoo<br /> <input name="strtrtoo" value="" size="50" type="text" /><br /> <br /> <input type='submit' name='submit' value='Submit'/><br> </form> </p> <?php $code = $_POST['code']; $number = $_POST['number']; $code2 = substr($code, $number); $strtrfrom = $_POST['strtrfrom']; $strtrtoo = $_POST['strtrtoo']; $submit= $_POST['submit']; if($code == "") echo ""; else { if($submit == "Submit") { echo "<textarea rows=\"8\" cols=\"50\">\n"; echo(strtr($code,$strtrfrom,$strtrtoo)); echo "</textarea>\n"; } } ?> Can anyone help? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170672-solved-strtr/ Share on other sites More sharing options...
Airhead315 Posted August 17, 2009 Share Posted August 17, 2009 you never output $number. You use it to set $code2 but then $code2 is never used either. Quote Link to comment https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900142 Share on other sites More sharing options...
newbtophp Posted August 17, 2009 Author Share Posted August 17, 2009 Soo would this solve it? <form action="index.php" method='post'> <p> Code<br /> <textarea name='code' rows="8" cols="50"></textarea><br> Number<br /> <input type="text" name="number" /><br /> strtrfrom<br /> <input name="strtrfrom" value="" size="50" type="text" /><br /> strtrtoo<br /> <input name="strtrtoo" value="" size="50" type="text" /><br /> <br /> <input type='submit' name='submit' value='Submit'/><br> </form> </p> <?php $code = $_POST['code']; $number = $_POST['number']; $code2 = substr($code, $number); $strtrfrom = $_POST['strtrfrom']; $strtrtoo = $_POST['strtrtoo']; $submit= $_POST['submit']; if($code == "") echo ""; else { if($submit == "Submit") { echo "<textarea rows=\"8\" cols=\"50\">\n"; echo(strtr($code2,$strtrfrom,$strtrtoo)); echo "</textarea>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900150 Share on other sites More sharing options...
newbtophp Posted August 18, 2009 Author Share Posted August 18, 2009 Hmm still not got it working, anyone can help? Quote Link to comment https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900693 Share on other sites More sharing options...
Daniel0 Posted August 18, 2009 Share Posted August 18, 2009 I can come over and wave my magic wand if you wish. It usually works. No, seriously, what are you trying to do? How can we make it work if we don't know what it's supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900721 Share on other sites More sharing options...
newbtophp Posted August 18, 2009 Author Share Posted August 18, 2009 Sorry Dan, for the bad description, its meant to use php's strtr function. Fill in the form and enter the number to read from and too and when submit is clicked it echos the result. Heres the code with added description: <form action="index.php" method='post'> <p> Code<br /> <textarea name='code' rows="8" cols="50"></textarea><br> Number<br /> <input type="text" name="number" /><br /> strtrfrom<br /> <input name="strtrfrom" value="" size="50" type="text" /><br /> strtrtoo<br /> <input name="strtrtoo" value="" size="50" type="text" /><br /> <br /> <input type='submit' name='submit' value='Submit'/><br> </form> </p> <?php //the code to the strtr on $code = $_POST['code']; //the number to read from $number = $_POST['number']; $code2 = substr($code, $number); //strtrfrom $strtrfrom = $_POST['strtrfrom']; //strtrtoo $strtrtoo = $_POST['strtrtoo']; //submit $submit= $_POST['submit']; if($code == "") echo ""; else { if($submit == "Submit") { //echo result echo "<textarea rows=\"8\" cols=\"50\">\n"; echo(strtr($code2,$strtrfrom,$strtrtoo)); echo "</textarea>\n"; } } ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900735 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.