0

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?

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 Commented Jan 31, 2020 at 21:49

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.