Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6477033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:53:55+00:00 2026-05-25T06:53:55+00:00

So here comes the problem: I want to paste an advertisement after a specified

  • 0

So here comes the problem:
I want to paste an advertisement after a specified ##th paragraph.

Let me show:

<p><img src="an/images/pic.jpg" /></p>
<p>Intro text</p>
<p>A paragraph</p>
<p>Another paragraph</p>

I want to paste the advertisement below the second paragraph. The final code should be like that:

<p><img src="an/images/pic.jpg /></p>
<p>Intro text</p>
<div>Yepp, let's make money</div>
<p>A paragraph</p>
<p>Another paragraph</p>

I tried some regexp but i don’t get it. Ladies and Gentlemen please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:53:55+00:00Added an answer on May 25, 2026 at 6:53 am

    Taking RegEx match open tags except XHTML self-contained tags into consideration you might want to use a DOM/HTML parser for this.

    <?php
    $doc = new DOMDocument;
    $doc->loadhtml( getHTML() );
    
    $xpath = new DOMXPath($doc);
    $ns = $xpath->query( '/html/body/p[2]' );
    if ( 0 < $ns->length ) {
        $parent = $ns->item(0)->parentNode;
        $nextSibling = $ns->item(0)->nextSibling;
    
        $p = $doc->createElement('p', 'Hi, this is Scott coming to you from another place and time');
        $parent->insertBefore($p, $nextSibling);
    }
    echo $doc->savehtml();
    
    function getHTML() {
    return '<html><head><title>...</title><body>
    <p><img src="an/images/pic.jpg" /></p>
    <p>Intro text</p>
    <p>A paragraph</p>
    <p>Another paragraph</p>
    </body></html>';
    }
    

    prints

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html><head><title>...</title></head><body>
    <p><img src="an/images/pic.jpg"></p>
    <p>Intro text</p><p>Hi, this is Scott coming to you from another place and time</p>
    <p>A paragraph</p>
    <p>Another paragraph</p>
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem here and I cant get it to work... I want
This question comes on the heels of the question asked here . The email
I am trying to understand this inline assembly code which comes from _hypercall0 here
What does the PCGPRLEN-1..28 means here?? Where does this 4 bit comes from? alt
I'm pretty much the rookiest rookie when it comes to Flash. Here's the actionscript
Why is it counter intuitive? /(?<!\d)\d{8}(?!\d)/ , here (?<!\d) comes first , but called
Here I'm pasting my codes where I want to retrieve Bundle version from my
I am having the following problem. I have the numbers 1/2/3/4/5/6 and I want
i want to create a modalpopup dynamically but i come across a problem.I pasted
Here is the problem: The way the GUI system I'm using works is as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.