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:

123|456

      

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:)

+3


source to share


1 answer


You can create a simple form:

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

      



How you can process the submitted form:

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

      

+3


source







All Articles