Re: [PHP] Half way

2008-10-23 Thread tedd

At 5:27 PM +0200 10/22/08, Jochem Maas wrote:

personally I prefer the solution where there is no ad shown at all.



I hear that -- I hate it when you develop a beautiful site for a 
client and then they want to hang ads off it -- and then complain 
about the site being too wide.


Can't win

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Half way

2008-10-22 Thread Ron Piggott
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.

Ron


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Half way

2008-10-22 Thread Ian
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.

Personally I prefer the later options as its probably easier ;)

Regards

Ian
-- 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Half way

2008-10-22 Thread Jochem Maas
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.

 Regards
 
 Ian


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Half way

2008-10-22 Thread Boyd, Todd M.
 -Original Message-
 From: Jochem Maas [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, October 22, 2008 10:27 AM
 To: [EMAIL PROTECTED]
 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Half way

2008-10-22 Thread Ashley Sheridan
On Wed, 2008-10-22 at 10:43 -0500, Boyd, Todd M. wrote:
  -Original Message-
  From: Jochem Maas [mailto:[EMAIL PROTECTED]
  Sent: Wednesday, October 22, 2008 10:27 AM
  To: [EMAIL PROTECTED]
  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
 
I think your best bet is to find the mid-point of the content (use Ians
suggestion of counting paragraphs) which can be done with a regular
expression to match p tags or br/br/ (sometimes you'll find double
line breaks instead of paragraph tags if content was copied from
Microshaft Word)

This should give you the character position which you can then use as an
offset in a replace function.


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php