WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need to take an advanced custom field textarea and display it in my template by breaking out each line separately. I want to wrap each line of the textarea with HTML, like an <li>.

I've tried the following, but it's just not working:

if (isset($instruction_textarea)){
    $arry=explode( "\r\n", $instruction_textarea );
for ($i = 0; $i <= count($arry); $i++){
    echo (trim($arry[$i])+"<br/>");
share|improve this question
up vote 2 down vote accepted

I would try something like this:

$lines = explode("\n", $instruction_textarea); // or use PHP PHP_EOL constant
if ( !empty($lines) ) {
  echo '<ul>';
  foreach ( $lines as $line ) {
    echo '<li>'. trim( $line ) .'</li>';
  echo '</ul>';

It should work.

share|improve this answer
Works like a charm, thank you good sir! :) – damrakred Jun 23 '13 at 20:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.