Hi,
Here is a function I came up with for inserting 2 images into a body of text. You can use the same principle for inserting your adsense.
PHP Code:
function array_insert($text, $pos, $image, $image2=null, $pos2=null) {
$text = split("[.]", $text);
$array2 = array_splice($text,$pos);
if($image !='<img src="images/" align="right" class="imagepad" />') {
$text[] = $image;
}
$array = array_merge($text,$array2);
if($image2 !='<img src="images/" align="left" class="imagepad" />') {
$array3 = array_splice($array,$pos2);
$array[] = $image2;
$array_double = array_merge($array,$array3);
$return = implode(" ", $array_double);
} else {
$return = implode(" ", $array);
}
return $return;
}
Explanation:
The function takes 3 required parameters:
$text, $pos, $image
(the other 2 are optional)
$text = the body of text
$pos = the position in paragraphs where you want the image or whatever
$image = the image name
usage:
PHP Code:
// eg $row['textbody'] from the database
echo array_insert($row['textbody'], 5, 'myimage.jpg');
would insert an image at the 5th paragraph break, obviously you could substitute the image for your adsense code 
Try it and see if it works for you!
Bookmarks