Jump to content

[SOLVED] Strtr


newbtophp

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/170672-solved-strtr/
Share on other sites

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";
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900150
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/170672-solved-strtr/#findComment-900735
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.