0

我有一个文本区域,其中包含如下信息,

Secured places in the national squad respectively
Selected to the national team this year as well
Selected to the national team twice during his university career
Went to school at ABS 

当用户单击提交按钮时,我想将每行中的字符串获取到提交页面中的 php 变量,就像这样

$a = "Secured places in the national squad respectively";
$b = "Selected to the national team this year as well";
$c = "Selected to the national team twice during his university career";
$d = "Went to school at ABS";

谁能告诉我该怎么做?

4

4 回答 4

2

如果您不关心句子,而关心换行符,那么您应该能够基于这样的方式分解为数组:

$posted_text = $_POST['text']; // or however you get the value into a string
$text_array = explode(PHP_EOL, $posted_text);
于 2012-08-21T21:09:22.920 回答
1

我想你在寻找

explode('\n\r', $var)

其中 var 是您撕开的值

于 2012-08-21T21:08:47.520 回答
0

没有断线的工作示例:


$words = explode(" ", str_replace("\n"," ",$text));
$sentences = Array();

$sentence = Array();
foreach($words as $word) {    
    $word = trim($word);
    if(!$word) continue ;
    $char1 = substr($word,0,1);
    $char2 = substr($word,1,1);

    if((strtoupper($char1) == $char1) && (strtolower($char2) == $char2)) {              
        if(count($sentence)) {
            $sentences[] = join(" ", $sentence);
        }        
        $sentence = Array();
    }    
    $sentence[] = $word;    
}
if(count($sentence)) {
    $sentences[] = join(" ", $sentence);
}        
于 2012-08-21T21:19:06.720 回答
0

您最好的选择是通过换行符 \n 爆炸字符串。不幸的是,如果用户实际上并没有按回车键并且文本刚刚滚动到下一行,则不会有任何换行符可以爆炸。

于 2012-08-21T21:09:10.877 回答