Problems sending multiple lines in a form

Asked

Viewed 28 times

-3

$lista = $_POST['lista'];
echo substr("$lista", 0, 28);
?>

<form action="" method="POST"> 
<textarea cols=60 rows="10" name="lista" maxlength="500" wrap="hard" placeholder="coragem, você consegue ! "></textarea>
<input type="submit" name="Envia" value="Enviar"> 
<input type="reset" name="Apaga" value="Apagar"> 

This is the second time I try to create and are closing for lack of details, please help a direction, because I honestly do not know what I can change to make it clearer...

I know it’s raw, but that’s basically it, I’m going to put a list of numbers separated by line and I need each line to have a character limitation.

My problem is: When I glue my list to it, only the first line is worked in PHP.

The number of lines will vary, I need each line in the list to be formatted equally, which has the same character numbers.

Example: By inserting the following list of numbers in textarea, I need you to return each line running the command substr("$lista", 0, 5) that is, each line is limited to only 5 characters.

11111111111111111111111111111
22222222222222222222222222222
33333333333333333333333333332
44444444444444444444444444444

In case it would return:

11111
22222
33333
44444

Currently, when entering my list of numbers, only the first line is executed, ie, returns only:

11111

Ignoring all other lines...

1 answer

-1


Hello, I believe you understand. I hope I can help you.

<?php
$lista = nl2br($_POST['lista']);
$dados = explode("\n",$lista);

foreach($dados as $linha){
    echo substr($linha, 0, 5)."<br>";
} 
?>
  • That’s exactly what it is!! Thank you very much, I didn’t understand the negatives, but anyway, I don’t know how to thank you for that, took a great weight off my back haha!! Thank you very much Junior.

Browser other questions tagged

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