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