Jump to content

Recommended Posts

Hi,

You know how some websites have a page of text and somehow in various places they put related adverts in it?
A bit like this tiny example:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]This is a 1st paragraphe of text

SOME FANCY AND ANNOYING ADVERT THAT DISTRACTS YOU FROM ARTICLE

This is another paragraphe[/quote]
How do they do it?

Is there a better way of doing it than using "ereg_replace" like this? (wouldn't it be great if one could put PHP scripts into a DB)

[code]//I get my normal text from db
$textfromdb="<p>This is a 1st paragraphe of text</p><p>This is another paragraphe</p>";
// search for paragraphe break
$searchtext="</p><p>"; //could be a specially inserted tag
//get my advert from db
$some_advert = "<img src="image.gif">"; //This would also come from a db
//do search and replace
$bodytext = ereg_replace ($textfromdb, $searchtext, $some_advert);
//output result
echo $bodytext;[/code]
Any suggestions?

By the way, I'm not using it for putting annoying adverts into text, I hate that but its a good example that we're all subject to, so easy to visualise.
I have a need to put dynamic stuff in the contents that comes out of a DB (from 1 table cell) such as display 1 client testimonial randomly selected from a list or a randomly selected illustration picked from a selection, examples go on...

Any suggestions how to do this a better way? Maybe some techique or function that I've never heard of...
... much appreciated!
Link to comment
https://forums.phpfreaks.com/topic/6571-adverts-in-articles/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.