How to iterate over multiline text in a textbox in php?

What I am trying to do is write a little helper application for myself that converts a coordinate list to a coordinate list in bb code, like this:

This is what the user will enter:



And the output will be:

1. [coord]123|456[/coord]


So basically I need something that will allow me to store multi-line text as a php variable and then iterate over that variable, changing each line like in the example above.

Please, help:)


source to share

1 answer

You can create a simple form:

<form method="post">
    <textarea name="multilineData"></textarea>
    <input type="submit" value="Submit">


How you can process the submitted form:

$output = '';
$num = 1;
foreach (explode(PHP_EOL, $_POST['multilineData']) as $row) {
    $output .= "$num. [coord]$row[/coord]<br>";
echo $output;




All Articles