RE: [PHP] Half way
| From: | Boyd, Todd M. | Date: | Wed, 22 Oct 2008 15:43:36 +0000 |
| Subject: | RE: [PHP] Half way | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282258@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jochem Maas [mailto:jochem@iamjochem.com]
> Sent: Wednesday, October 22, 2008 10:27 AM
> To: php_list@FishNet.co.uk
> Cc: PHP General
> Subject: Re: [PHP] Half way
>
> Ian schreef:
> > On 22 Oct 2008 at 6:34, Ron Piggott wrote:
> >
> >> I am tweaking a blog application I have programmed. I am trying to
> >> display a Google ad half through the blog entry, at the first
> available
> >> <br />.
> >>
> >> The code I use so far is:
> >>
> >> $half_way = strlen( nl2br(stripslashes($entry))) /2 ;
> >> $ad_position = strpos ( nl2br(stripslashes($entry)) , "<br />" ,
> >> $half_way );
> >> echo substr( nl2br(stripslashes($entry)) , 0, $ad_position);
> >>
> >> Is there a way to modify my strpos syntax to check and see if the
> >> nearest <br /> is before the half way mark?
> >>
> >> What is tending to happen is the ad is being placed 5/7ths of the
> way
> >> through the blog entry because of the length of the paragraph the
> half
> >> way character falls in. Visually it doesn't look balanced. I
would
> >> prefer the ad display 4/7th of the way through the blog entry in
> those
> >> situations.
> >>
> >> Thanks for helping me.
> >
> > Hi,
> >
> > Disclaimer: Without seeing the actual blog entry this is all guess
> work!
> >
> > Your code above seems to find the half way point in the raw text.
> This is all very well if
> > you do not have paragraphs or other formatting code that can move
> text around once
> > displayed.
> >
> > To overcome this you will have to try and detect the number of
> paragraphs (or formatting
> > code) before the half way point and after it and try and move the
> Google Ad entry to
> > accommodate this.
> >
> > This will involve trial and error to determine an algorithm that
best
> matches your blog
> > entries.
> >
> > Or you could go down the easy route and add some sort of marker
> (database entry or a
> > tag of some sort) to each blog which indicates were the Google ads
> should go.
>
> yeah, hack the WYSWYG editor to add an extra button that inserts a
> marker (e.g. specific
> HTML comment) which you can replace ... WordPress has a tinyMCE hack
> that does something
> like this although in that case it's used to insert markers that allow
> the content to
> be split into multiple pages.
>
> > Personally I prefer the later options as its probably easier ;)
>
> personally I prefer the solution where there is no ad shown at all.
If it's blogging software he wrote, that doesn't necessarily mean that
it's blogging software he uses exclusively. :) Perhaps he is
distributing this to a user base, or hosting the solution for users on a
web server of his own. If this is the case, then allowing the user (who
will receive no compensation for these ads, I might add--no pun
intended) to decide where the advertisement will go--or if it will go in
at all!--might be counterproductive.
Maybe I misunderstood.
Todd Boyd
Web Programmer