php - Is there a built-in function to generate multiple paragraph tags based on a string with new line separators?

Consider the following code<?php The new line separated string$section_string = <<<EOLSentence A1. Sente

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?

Share Improve this question edited Jan 28, 2020 at 21:58 Abel Melquiades Callejo asked Jan 28, 2020 at 21:52 Abel Melquiades CallejoAbel Melquiades Callejo 1841 gold badge1 silver badge15 bronze badges 2
  • 1 Have you tried apply_filters('the_content', $section_string)? That should apply wp_autop which would add either <p> tags or <br>s. – WebElaine Commented Jan 28, 2020 at 22:48
  • @WebElaine that worked like a charm! Exactly what was needed. It added the <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
Add a comment  | 

1 Answer 1

Reset to default 1 +50

Have 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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信