Half way
| From: | Ron Piggott | Date: | Wed, 22 Oct 2008 10:34:03 +0000 |
| Subject: | Half way | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-282241@lists.php.net to get a copy of this message | ||
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