svincent2000
10-17-2002, 10:19 PM
$body = "some words some words some words some words <img src=\file.name string > some more words<img src=\file.name string >";
// need to remove img tags from the total body text
do {
$i = $i + 1;
$startpos = strpos($body, "<img", $startpos);
$endpos = strpos($body, ">", $startpos);
$length = ($endpos + 1) - $startpos;
$final = substr ($body, $startpos, $length);
$startpos = $endpos;
$body = str_replace ($final, "", $body);
}
while ((strpos("<img", $startpos) != false));
I am trying to strip out HTML image tags that start "<img" and end ">" (like they do). If I have additional HTML tags (like "<p>") the do...while statement stops - why? How can I get round this? I thought I'd scripted it so that it ONLY looks for and removes <img ... >
my alternative code is:
$startpos = 0;
$i = 0;
$count_img_tag = substr_count($body, "<img");
for ($i = 1; $count_img_tag; $i++)
{
$startpos = strpos($body, "<img", $startpos);
$endpos = strpos($body, ">", $startpos);
$length = ($endpos + 1) - $startpos;
$final = substr ($body, $startpos, $length);
$startpos = $endpos;
$body = str_replace ($final, "", $body);
}
Any help and suggestions please...
Simon
// need to remove img tags from the total body text
do {
$i = $i + 1;
$startpos = strpos($body, "<img", $startpos);
$endpos = strpos($body, ">", $startpos);
$length = ($endpos + 1) - $startpos;
$final = substr ($body, $startpos, $length);
$startpos = $endpos;
$body = str_replace ($final, "", $body);
}
while ((strpos("<img", $startpos) != false));
I am trying to strip out HTML image tags that start "<img" and end ">" (like they do). If I have additional HTML tags (like "<p>") the do...while statement stops - why? How can I get round this? I thought I'd scripted it so that it ONLY looks for and removes <img ... >
my alternative code is:
$startpos = 0;
$i = 0;
$count_img_tag = substr_count($body, "<img");
for ($i = 1; $count_img_tag; $i++)
{
$startpos = strpos($body, "<img", $startpos);
$endpos = strpos($body, ">", $startpos);
$length = ($endpos + 1) - $startpos;
$final = substr ($body, $startpos, $length);
$startpos = $endpos;
$body = str_replace ($final, "", $body);
}
Any help and suggestions please...
Simon