Get each line from textarea

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


$         


        
8条回答
  •  孤城傲影
    2020-12-04 11:22

    Use PHP DOM to parse and add
    in it. Like this:

    $html = '';
    
    //parsing begins here:
    $doc = new DOMDocument();
    @$doc->loadHTML($html);
    $nodes = $doc->getElementsByTagName('textarea');
    
    //get text and add 
    then remove last
    $lines = $nodes->item(0)->nodeValue; //split it by newlines $lines = explode("\n", $lines); //add
    at end of each line foreach($lines as $line) $output .= $line . "
    "; //remove last
    $output = rtrim($output, "
    "); //display it var_dump($output);

    This outputs:

    string ' put returns between paragraphs
    
    for linebreak add 2 spaces at end
    indent code by 4 spaces
    quote by placing > at start of line ' (length=141)

提交回复
热议问题