Remove white space php

0

When typing values (one per line), example:

    valor1
    valor2
    valor3
    valor4

It will return: value1, value2, value3, value4

entra_valores.php

    <html>
    <body> 
    <form action="junta.php" method="post">
    <textarea rows="10" cols="50" name="valores">
    </textarea><br>
    <input type="submit" name="enviar" value="Pronto" />
    </form>
    </body> 
    </html>

junta.php

    <?php
    $valores = $_POST['valores'];
    $quebra = explode("\n", $valores);
    $junta = implode(',', $quebra);
    $valores = preg_replace("/\s+/", "", $junta);
    echo $valores;
    ?>
    
asked by anonymous 19.08.2018 / 11:19

1 answer

1

Well, if you want to remove ALL of the blanks, you can use a regular expression.

$valores = preg_replace("/\s+/", "", $_POST["valores"]);
    
19.08.2018 / 17:34