admin管理员组文章数量:1392073
Consider the following code
<?php
// The new line separated string
$section_string = <<<EOL
Sentence A1. Sentence A2. Sentence A3.
Sentence B1. Sentence B2. Sentence B3.
Sentence C1. Sentence C2. Sentence C3.
EOL;
// Is there a function you can call like so:
$html_markup = unknown_awesome_function( $section_string );
echo $html_markup;
?>
Expected output
<p>Sentence A1. Sentence A2. Sentence A3.</p><p>Sentence B1. Sentence B2. Sentence B3.</p><p>Sentence C1. Sentence C2. Sentence C3.</p>
Instead of the example fictional unknown_awesome_function()
, is there a built-in function you can call to generate multiple <p>
tags based on a string with new line separators?
Consider the following code
<?php
// The new line separated string
$section_string = <<<EOL
Sentence A1. Sentence A2. Sentence A3.
Sentence B1. Sentence B2. Sentence B3.
Sentence C1. Sentence C2. Sentence C3.
EOL;
// Is there a function you can call like so:
$html_markup = unknown_awesome_function( $section_string );
echo $html_markup;
?>
Expected output
<p>Sentence A1. Sentence A2. Sentence A3.</p><p>Sentence B1. Sentence B2. Sentence B3.</p><p>Sentence C1. Sentence C2. Sentence C3.</p>
Instead of the example fictional unknown_awesome_function()
, is there a built-in function you can call to generate multiple <p>
tags based on a string with new line separators?
1 Answer
Reset to default 1 +50Have you tried apply_filters('the_content', $section_string)
? That should apply wp_autop which would add either <p>
tags or <br>
s.
本文标签:
版权声明:本文标题:php - Is there a built-in function to generate multiple paragraph tags based on a string with new line separators? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780710a2624694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
apply_filters('the_content', $section_string)
? That should applywp_autop
which would add either<p>
tags or<br>
s. – WebElaine Commented Jan 28, 2020 at 22:48<p>
tag, not the<br>
. Would you mind posting it as an answer? I'd like to give you some bounty for the awesome response. Thanks – Abel Melquiades Callejo Commented Jan 31, 2020 at 21:49