0

I"m making a custom RSS feed and need a way to strip HTML tags from a custom code that grabs the first paragraph from a post.

This is what I'm using:

<?php
                    $paragraphAfter = 1; // shows image after paragraph 1
                    $paragraphsShow = 1; // shows first two paragraphs
                    $content = apply_filters('the_content', get_the_content());
                    $content = explode("</p>", $content);
                    $max = (count($content) < $paragraphsShow) ? count($content) : $paragraphsShow;
                    for ($i = 0; $i < $max; $i++) {
                        echo $content[$i] . "</p>";
                    if ($i == ($paragraphAfter-1)) {
                } } ?>
4
  • php.net/manual/en/function.strip-tags.php ? Commented Sep 27, 2015 at 8:28
  • Please format you code for better readeable, thanks.
    – birgire
    Commented Sep 27, 2015 at 9:15
  • do you only want to get the first para without the tags?
    – terminator
    Commented Sep 27, 2015 at 10:16
  • How do I save PHP code in a string? Tried <?php $test = '<?php echo test ?>'?> and it didn't work. Commented Sep 27, 2015 at 21:36

1 Answer 1

0

Following Mark Kaplun advice, I fixed my problem. Just wish there was a way to like a comment.

<?php
                    $paragraphAfter = 1; // shows image after paragraph 1
                    $paragraphsShow = 1; // shows first two paragraphs
                    $content = apply_filters('the_content', get_the_content());
                    $content = explode('</p>', $content);
                    $max = (count($content) < $paragraphsShow) ? count($content) : $paragraphsShow;
                    for ($i = 0; $i < $max; $i++) {
                        echo **strip_tags($content[$i])** . '</p>';
                    if ($i == ($paragraphAfter-1)) {
                } } ?>

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.