Jump to content

[SOLVED] Search for all img tags and replace with " "


TGWSE_GY

Recommended Posts

Hey guys,

 

I am wondering if I have a string that has html in it and I only want to strip out the IMG TAGS and cut the string down to the first 570positions. how I would do this I thought that I had it with this

 

//Get article from db
$query = "SELECT article FROM sndsurf_news ORDER BY date DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$resultarray = mysql_fetch_assoc($result) or die(mysql_error());
$article = $resultarray['article'];

//Initialize $replace variable set to NULL
$replace = " ";
//Remove all instances of the html img tag
substr_replace("/<img[^>]+\>/i", $replace, $article); 

$summary = substr($article, 0, 570);
echo $summary;

 

But the images still display. Any thoughts?

 

Thanks

George!

I got it to work with the following code

 

<?php
        //Get article from db
$query = "SELECT article FROM sndsurf_news ORDER BY date DESC LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
$resultarray = mysql_fetch_assoc($result) or die(mysql_error());
$article = $resultarray['article'];

//these are tags that are ALLOWED.
$stripedarticle = strip_tags($article, '<a><b><i><u><center><p><s><strike><strong><em><h1><h2><h3><h4><h5><h6><font><table><span>');
$summary = substr($stripedarticle, 0, 480);
$readmore = "<a href=\"index2.php?section=news\"><b>....Read More</b></a>";
echo $summary . $readmore;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.