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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744780710a4593321.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