简体   繁体   English

如何在php中的文本框中迭代多行文本?

[英]How to iterate over multiline text in text box in php?

What I am trying to do is I want to write a little helper application for myself, which will convert list of coordinates into list of coordinates in bb code, like so: 我想要做的是我想为自己编写一个小帮助应用程序,它将坐标列表转换为bb代码中的坐标列表,如下所示:

This is what user will input: 这是用户输入的内容:

123|456

And the output will be: 输出将是:

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

So basically I need something that will allow me to store the multiline text as a php variable, and then to iterate over that variable changing each line like in the example above. 所以基本上我需要的东西允许我将多行文本存储为php变量,然后迭代该变量来改变每一行,如上例所示。

Please help :) 请帮忙 :)

You can create simple form: 您可以创建简单的表单:

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

Than you can process submitted form: 比你可以处理提交的表格:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM