Re: Finding split points in an article for inserting ads
| From: | Simon J Welsh | Date: | Tue, 15 Feb 2011 21:38:22 +0000 |
| Subject: | Re: Finding split points in an article for inserting ads | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311328@lists.php.net to get a copy of this message | ||
On 16/02/2011, at 10:03 AM, Brian Dunning wrote:
> Hey all -
>
> I've got long articles, the HTML for which comes out of MySQL. Works great. I want to
> split it up so that I can insert ad blocks at various points within it. The articles are all pretty
> long but they're of variable length. I want to chop them up into three close-to-equal
> (doesn't have to be) chunks of paragraphs, thus:
>
> <p>Here's the original article</p>
> <p>Here's the original article</p>
> <p>Here's the original article</p>
> <p>Here's the original article</p>
> <p>Here's the original article</p>
>
> Would become:
>
> <p>Here's the original article</p>
> <p>Here's the original article</p>
> <?php include('first_ad'); ?>
> <p>Here's the original article</p>
> <p>Here's the original article</p>
> <?php include('second_ad'); ?>
> <p>Here's the original article</p>
>
> Any suggestions? Thanks.
Assuming you're only using <p> tags, count the number of opening <p> tags, divide
by three. First ad block goes after the round($amount/3)-th </p>, second ad block goes after
the round($amount/3*2)-th </p>.
---
Simon Welsh
Admin of http://simon.geek.nz/
Who said Microsoft never created a bug-free program? The blue screen never, ever crashes!
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e