Get each line from textarea

前端 未结 8 1748
盖世英雄少女心
盖世英雄少女心 2020-12-04 10:42


$         


        
相关标签:
8条回答
  • 2020-12-04 11:43

    You could use PHP constant:

    $array = explode(PHP_EOL, $text);
    

    additional notes:
    1. For me this is the easiest and the safest way because it is cross platform compatible (Windows/Linux etc.)
    2. It is better to use PHP CONSTANT whenever you can for faster execution

    0 讨论(0)
  • 2020-12-04 11:43

    It works for me:

    if (isset($_POST['MyTextAreaName'])){
        $array=explode( "\r\n", $_POST['MyTextAreaName'] );
    

    now, my $array will have all the lines I need

        for ($i = 0; $i <= count($array); $i++) 
        {
            echo (trim($array[$i]) . "<br/>");
        }
    

    (make sure to close the if block with another curly brace)

    }
    
    0 讨论(0)
提交回复
热议问题