简体   繁体   中英

PHP counting each new line In textarea field as a new line and wrapping in a list item

I am using a textarea (advanced custom fields) to capture the users selection.

So the user first answers if there are education areas nearby - yes/no then triggers a radio input with numbers from 1-10, then depending on that, i need to return my information. Right now i am just showing the returned input for the selection of 1 education area.

What want to do, is count the spaces in the text area and wrap each line around an <li> $var </li> . My code below is only returning the second half of my textarea input.

My textarea is:
School
Distance

The below code is only returning

<li>Distance</li>

My Code

if( $edu_close == 'Yes' ) { 
        
        $lines = explode("\n", $edu_close1);
        $count = count ($mylines);

        foreach ( $lines as $line ) {
        $isedu = '<li>'.$lines.'</li>';    
    }

}

elseif( $edu_close == 'No' ) { 

    $noedu = 'Nothing Found';
    
}

    $poidetails .= $isedu;
    $poidetails .= $noedu;
    return $poidetails;

Textarea

Result

Am I doing something wrong that it is only reading the end of the textareas input?

you are overwriting $isedu in every cycle. you should have it like this

...
$isedu .= '<li>'.$lines.'</li>';
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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