Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 1 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

 
discard

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.