Jump to content

Don't count <p> inside a blockqoute


CRUSO
 Share

Recommended Posts

Hello guys! I use a function that inserts an ad after X number of paragraphs. I want everything that is between
[blockquote] and [/blockquote] to be counted only as 1 paragraphs despite what is inside [blockquote]. I cant really find a solution.

 

function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content );
    foreach ($paragraphs as $index => $paragraph) {

        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }


        if ( ( ($index + 1) % $paragraph_id ) == 0 ) {
            $paragraphs[$index] .= $insertion;
        }
      
    }

    return implode( '', $paragraphs );

}

 

Link to comment
Share on other sites

12 hours ago, gw1500se said:

You probably would make life easier for yourself if you use DOMDocument. However, it seems like you should just include a check for "<blockquote>" then ignore everything until you find "</blockquote>".

Can you make me a function with DOMDocument? I'm just an amateur in php.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.