Forum Moderators: coopster

Message Too Old, No Replies

Inserting an Image after X characters

         

internetheaven

4:41 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to insert an image code after 1500 characters of a string. I tried using:

$string = preg_replace("/^(.{1500})/", "$1<img src='/images/image.gif' align='left' border='0'>", $string);
echo $string

which didn't work. However:

$string = preg_replace("/^(.{200})/", "$1<img src='/images/image.gif' align='left' border='0'>", $string);
echo $string

did work. Various other numbers would work on other pages but I can't place my finger on why certain pages won't work past a certain number. It varies from page to page.

What should I be looking for?

Readie

5:19 pm on Apr 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, I think perhaps you could try this:
function insert_after_x($input, $chars, $ins) {
$chunk_one = substr($input, 0, $chars);
$chunk_two = substr($input, $chars);
$output = $chunk_one . $ins . $chunk_two;
return $output;
}
Where $input is the string you want to insert into, $chars is after how many characters you want to insert the image, and $ins is what you want to insert into it.