admin管理员组文章数量:1425820
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
1 Answer
Reset to default 6I 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.
本文标签: phpHow to Explode a Textarea Field and Echo each line separatelywrapped with HTML
版权声明:本文标题:php - How to Explode a Textarea Field and Echo each line separately, wrapped with HTML 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745415803a2657679.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论