Position ads or images within a block of non-editable text

I want to scatter various images and ads within a giant <div> of text. The twist here is that the text comes from a database, and I can’t edit the HTML to place the elements where I want them. So if I just float them normally they all end up at the bottom of the article. For SEO reasons I’m hoping to find a solution that lets me put the ad content below the text in the HTML.

The pages are all long enough that I could position:absolute them, and that would work if I could find a way to wrap the text around them.

Any suggestions?

The pages are all long enough that I could position:absolute them, and that would work if I could find a way to wrap the text around them.

Hi,
Text will only wrap around floats, trying to use absolute positioning would cause more problems for you.

Here is a very rough possible solution.

  1. explode all your text into an array.
  2. calculate how much text is in a section,
  3. create a for next loop for all sections
  4. call print_section($atext, $start, $stop)
    
  5. include your advert_001.php
    
  6. endloop

<?php
//======================
function display($atext, $start, $stop)
{
  for ($i2=$start; $i2<=$stop; $i2++)
  {
    echo $atext[$i2] . ' ';     
  }
}

// dummy text to see if it works
$t = 'This is a test to see if it works and is to be replaced with text from your database.';
$t = $t.$t.$t.$t.$t;

$a = explode(' ', $t ); 
$cnt = count($a);
$partial = $cnt % 5;

for($x=0; $x<=$partial; $x++)
{
  display($a, $x * $partial, ($x +1) * $partial);
  echo '<p>include (your_advert_here.php) </p>';
}


Output:

This is a test to

include (your_advert_here.php)

to see if it works.This

include (your_advert_here.php)

works.This is a test to

include (your_advert_here.php)

to see if it works.This

include (your_advert_here.php)

works.This is a test to

include (your_advert_here.php)