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

あなたの最善の策は、改行文字 \n を介して文字列を分解することです。残念ながら、ユーザーが実際に Enter キーを押さずにテキストが次の行に移動した場合、爆発する改行文字はありません。

于 2012-08-21T21:09:10.877 に答える
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 に答える