IBM developerWorks
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old July 24th, 2004, 11:33 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
a little help with a code for ads

Hi,
I was wondering if someone could help me with a code by showing an example. I have a site with tons of articles on it and I want to have ads appear in mid article, kind of like news websites do. Someone told me I could use explode to find all the instances of </P> so I know where the end of each paragraph lies. The idea is to insert a paragraph with an adcode in it after say the third or fourth paragraph. I'm not really sure how to count the number of times </p> shows up and how to choose say the fourth time to insert my adcode.

I'm kind of a newbie. That's why I asked for an example because then I could pick it apart and learn by example. Hope someone can show me the way.

Thanks/
__________________
Without me my guitar is useless
--
http://www.guitarnoise.com
http://www.musiccareers.net

Reply With Quote
  #2  
Old July 25th, 2004, 06:05 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
I'm sure there are tutorials about how to do this kind of thing. Have you run a google search for it and looked around php tutorial sites? After you've done that I'm sure you'll find similar things at the very least. Use that and give it a go then ask us specific questions since its unlikely anyone here will just write your code for you.

-KM-

Reply With Quote
  #3  
Old July 26th, 2004, 02:34 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thanks for the reply. I guess I was getting hopeful that someone might write code for me. I did search google and go through numerous tutorials before posting here. I've tried really hard to get the desired result on my own but there are a lot of concepts I haven't grasped yet.

I have come up with the following code I learned from an example:

PHP Code:
// The Text phrases to split
$text "$articletext";

// Call the Function Explode and Set it to a variable, Telling the explode function by what charecter to seperate it, and what text to seperate
$ExplodeIt explode("</p>","$text");

// Lets get a Count Of the total Values in the array.

$Count count($ExplodeIt);

// Create a Loop to Output the Information. Make sure $i starts off at 0, this is where the first value is returned
for ($i=0$i $Count$i++) {

// Output the Information. Remember, It is looping so as many items that are in the array will do this loop that many times.
echo "<p><ad code goes here> $ExplodeIt[$i]</P>";




What this does is place the ad code after each paragraph. The looping has me confused. What expression shoul I be looking for to get the adcode to appear only once, and after a </P> of my choice? I don't mind trying to figure it out myself, but a push in the right direction would be greatly apreciated.

Reply With Quote
  #4  
Old July 26th, 2004, 03:18 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
Good work, only a small change to get what you want in there -

PHP Code:
// which paragraph to output under (3 in this example)
$ad_paragraph 3;

// The Text phrases to split 
$text "$articletext"

// Call the Function Explode and Set it to a variable, Telling the explode function by what charecter to seperate it, and what text to seperate 
$ExplodeIt explode("</p>","$text"); 

// Lets get a Count Of the total Values in the array. 

$Count count($ExplodeIt); 

// Create a Loop to Output the Information. Make sure $i starts off at 0, this is where the first value is returned 
for ($i=0$i $Count$i++) { 

// Output the Information. Remember, It is looping so as many items that are in the array will do this loop that many times. 
  
if ($i == $ad_paragraph)
    echo 
"<p><ad code goes here> $ExplodeIt[$i]</P>";
  else
    echo 
"<p>$ExplodeIt[$i]</P>";



Hope this helps,

-KM-

Last edited by kode_monkey : July 26th, 2004 at 03:20 AM. Reason: Writing code too early in the morning...

Reply With Quote
  #5  
Old July 26th, 2004, 03:57 AM
guitarnoise guitarnoise is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 32 guitarnoise User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Cool. After banging my head against the wall for a while I came up with something that works as well. I wanted to post it here then saw your reply. I was wondering which is more efficient, my code or yours?

PHP Code:
// The Text phrases to split
   
$text "$articletext";

// Call the Function Explode and Set it to a variable, Telling the explode function by what character to seperate it, and what text to seperate
   
$ExplodeIt explode("</p>","$text");

// Lets get a Count Of the total Values in the array.
   
$Count count($ExplodeIt);

// Create a Loop to Output the Information. Make sure $i starts off at 0, this is where the first value is returned
   
for ($i=0$i $Count$i++) {

// Output the Information. Remember, It is looping so as many items that are in the array will do this loop that many times.
   
echo "$ExplodeIt[$i]";
     if (
$i == 2) {
       echo(
"<P>&nbsp;");
       include(
"my_adcode");
       echo(
"&nbsp;</p>");       
       }
   } 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > a little help with a code for ads


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway