php - How to Explode a Textarea Field and Echo each line separately, wrapped with HTML

Need to take an advanced custom field textarea and display it in my template by breaking out each line separately. I wan

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/>");
}

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 edited Jun 23, 2013 at 20:25 Milo 79k4 gold badges128 silver badges168 bronze badges asked Jun 23, 2013 at 19:44 adsfadsf 872 gold badges4 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 6

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745415804a4626743.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信