Substituting and displaying parameters in PHP

Asked

Viewed 28 times

0

I’m creating a coder, a personal project to apply knowledge and learn more.

The coding part is working, but the decoding part isn’t. I execute and nothing appears.

Could someone help me find the problem?

<div id="area">
    <form method="POST" action="resultado.php">
        <fieldset><label> <h2 class="a"> Escolha uma opção: </h2> </label>
            <input type="radio" name="condiçao" id="codificar" value="codificar"> <label for="codificar">Codificar</label>
            <input type="radio" name="condiçao" id="decodificar" value="decodificar"> <label for="decodificar">Decodificar</label>
        </fieldset>
        <label> <h2 class="a">Digite o texto:</h2> </label>
        <textarea name= "txt" class="cod" cols="100%" rows="20" > </textarea>
        <br>
        <button> ENVIAR </button>
    </form>
    </div>
    
    <?php
    echo "<h2> Resultado: </h2>";
    $condiçao = isset($_POST["condiçao"])?$_POST["condiçao"]:" ";
    $txt = isset($_POST["txt"])? trim($_POST["txt"]):" ";
    //conta
    $cont = str_word_count($txt);
    //divide
    $v= explode(" ", $txt);
    //junta
    //inicio contador
    $i = 0;
    while ($i>$cont) {
        if($v[$i] == "21UO4UTYEP"){
            echo "A";
        }    
        elseif ($v[$i] == "IPDQXS1QGL") {
            echo "B";
        }
        $i++;
    }
    ?>
  • In your while is wrong while ($i>$cont) { needs to be while ($i<$cont) {

  • I can’t believe I didn’t notice. Thanks man

  • Don’t worry, it happens. When catching on to something, the tip is to stop and go do something else, then when you come back you need to read the code word by word you find these things. I’ve been there a few times in this 20 years of programming.

1 answer

0


You assign the value of $cont equal to the number of words and the value $i equal to 0, then you say while $i is greater than $cont.

Your code never enters the loop, $i will never be bigger than the counter.

Reverses.

while($i < $cont){}
  • I can’t believe I didn’t notice that. THANK YOU

Browser other questions tagged

You are not signed in. Login or sign up in order to post.