admin管理员组文章数量:1122846
I have added a custom metabox that holds string from a textarea in database. Now if I just simply echo the meta box like this:
$post_meta = get_post_meta($pid);
$answer = $post_meta["answer"][0];
echo $answer;
the html tags would be escaped and the text would appear like this:
blah blah blah <ul><li>blah blah</li><li>blah</li></ul>
As you see the html tags get escaped and they appear as string so I use php like this:
$answer = html_entity_decode($answer);
Now the html tags work as they are expected but there remains one problem. In order to get the line breaks from the database I add another line like this:
$answer = nl2br($answer);
which solves the problem with line breaks but add a new line break between each li tags.
Any idea how to resolve this? I need line breaks but at the same time would want to avoid adding a line break between li tags.
UPDATE: for the moment I added this line of php after nl2br and I got the result
$answer = preg_replace("!</li>[\s\S]{1,100}?<!", "</li><", $answer);
But I don't think this is the right way to go.
I have added a custom metabox that holds string from a textarea in database. Now if I just simply echo the meta box like this:
$post_meta = get_post_meta($pid);
$answer = $post_meta["answer"][0];
echo $answer;
the html tags would be escaped and the text would appear like this:
blah blah blah <ul><li>blah blah</li><li>blah</li></ul>
As you see the html tags get escaped and they appear as string so I use php like this:
$answer = html_entity_decode($answer);
Now the html tags work as they are expected but there remains one problem. In order to get the line breaks from the database I add another line like this:
$answer = nl2br($answer);
which solves the problem with line breaks but add a new line break between each li tags.
Any idea how to resolve this? I need line breaks but at the same time would want to avoid adding a line break between li tags.
UPDATE: for the moment I added this line of php after nl2br and I got the result
$answer = preg_replace("!</li>[\s\S]{1,100}?<!", "</li><", $answer);
But I don't think this is the right way to go.
Share Improve this question edited Sep 26, 2018 at 12:17 agahi asked Sep 26, 2018 at 8:09 agahiagahi 1013 silver badges12 bronze badges2 Answers
Reset to default 0To add line-breaks inside <textarea>
(but not on front-end output), use this inside textarea
:
echo str_replace('</li>',"</li>\r\n", $answer);
Why don't you use <?php esc_textarea( $answer ); ?>
本文标签: custom fieldOutputing a metabox textarea and avoid line breaks inside li tags
版权声明:本文标题:custom field - Outputing a metabox textarea and avoid line breaks inside li tags 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736285247a1927420.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论