CRUSO Posted September 24, 2021 Share Posted September 24, 2021 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 ); } Quote Link to comment Share on other sites More sharing options...
gw1500se Posted September 24, 2021 Share Posted September 24, 2021 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>". Quote Link to comment Share on other sites More sharing options...
requinix Posted September 25, 2021 Share Posted September 25, 2021 +1 for DOM. If you want to insert an ad between paragraphs then you likely want to insert it between top-level paragraphs, and simple iteration on the top node's children will do the job quite easily. Quote Link to comment Share on other sites More sharing options...
CRUSO Posted September 25, 2021 Author Share Posted September 25, 2021 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 25, 2021 Share Posted September 25, 2021 Have a try with simple_html_dom class Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.