Results 1 to 7 of 7

Thread: Insert Ad Code Within Page

  1. #1
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055

    Insert Ad Code Within Page

    Anyone have preexisting code to find the first occurence of </p> in an article and then insert adcode after it? Don't want to reinvent the wheel if I don't have to.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  2. #2
    Registered
    Join Date
    Apr 2006
    Posts
    184
    Eh, there's probably a more efficient way of doing it (but regular expressions confuse the hell out of me), but off the top of my head....

    Code:
    // where $article is... erm... your article. ;)
    $arr = explode("</p>", $article);
    $arr[1] = "your add code here".$arr[1];
    $article = implode("</p>", $arr);
    echo $article;
    Last edited by KelliShaver; 06-21-2006 at 12:32 PM.

  3. #3
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    This should do what you are after:

    Code:
    $content = preg_replace('<\</p\>>', '</p>'.$square_ad, $content, 1);
    Just appends '$square_ad' after the first '</p>'. In my case, '$square_ad' was Adsense code.

  4. #4

  5. #5
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    I assume with yours I could just change the final argument to be whichever paragraph I want?
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  6. #6
    Future AstonMartin driver r2d2's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    1,608
    Looking at the preg_replace page, it looks like changing it to 3 for example would put an ad after first, second and third - not just the third.

    KelliShaver's should be easier to do something like that, eg:

    Code:
    $arr[3] = "your add code here".$arr[3];
    would put it after third I believe.

  7. #7
    Registered
    Join Date
    Apr 2006
    Posts
    184
    Yep. What it's doing is appending it to the beginning of the 4th paragraph (the array count starts at 0).

    You could also do:

    Code:
    $arr[2].="yoour ad code";
    to append it to the end of the 3rd. It really makes no difference which you do, and I really don't know why I did it one way and not the other in the example above.
    Last edited by KelliShaver; 06-21-2006 at 05:13 PM.

Similar Threads

  1. Is any other method to get Website PR ?
    By number7 in forum Search Engine Optimization
    Replies: 10
    Last Post: 01-08-2019, 03:33 AM
  2. Free Host - 2,000,000 Page Views - 900,0000 Visitors
    By Todd W in forum The Marketplace
    Replies: 0
    Last Post: 10-23-2005, 08:35 PM
  3. Html code help needed
    By loveinstar in forum HTML, CSS, Layout, and Design
    Replies: 2
    Last Post: 04-12-2005, 08:00 PM
  4. Interesting Website Code I Found
    By grichards in forum Search Engine Optimization
    Replies: 2
    Last Post: 12-10-2003, 09:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •