TGWSE_GY Posted August 3, 2009 Share Posted August 3, 2009 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! Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted August 3, 2009 Share Posted August 3, 2009 I think that works fine just replace substr_replace --> preg_replace. Quote Link to comment Share on other sites More sharing options...
TGWSE_GY Posted August 4, 2009 Author Share Posted August 4, 2009 Its still displaying the images?????? its like it is skipping over the img tags all together. lol Thanks Quote Link to comment Share on other sites More sharing options...
TGWSE_GY Posted August 4, 2009 Author Share Posted August 4, 2009 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; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.