jaxdevil Posted May 26, 2008 Share Posted May 26, 2008 I need to remove anything that is a '<' or a '>' or anything that comes between those two symbols in my query (like < br > or < li > or < hr > etc.). In my database the field 'description' contains text that is html formated so when it display it is in lines, and has breaks, etc. What I need to do is remove all of that HTML formating for this particular query. I am sure there is some simple way. Anyone know how to do this? I am sure it is something like a replace function but I can't figure it out. Any ideas? I copied my ENTIRE code below. The row query I am trying to remove those html codes from is $row['description'] Thanks for any help you can give! <?php mysql_connect('localhost','xxx','xxx'); mysql_select_db('xxx') or die(mysql_error()); ?> <? header("Content-Type: application/rss+xml"); ?> <? echo "<?";?>xml version="1.0" encoding="UTF-8"<? echo "?>";?> <rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link> <?php $sql = "SELECT * FROM products WHERE `active`='Yes' ORDER BY `cats` LIMIT 5" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $cat = end($cats); ?> <item><title><?=$row['man']?> <?=$row['mod']?> <?=$row['name']?></title> <g:brand><?=$row['mod']?></g:brand> <g:condition>new</g:condition> <g:description><?=$row['description']?> <?=$row['details']?></g:description> <g:model_number><?=$row['mod']?></g:model_number> <g:id><?=$row['mod']?></g:id> <g:image_link><?=$row['img_url']?></g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=<?=$row['mod']?></g:link> <g:mpn><?=$row['mod']?></g:mpn> <g:price><?=$row['price']?></g:price> <g:product_type><?=$cat?></g:product_type> <g:upc><?=$row['upc']?></g:upc> <g:quantity>1000</g:quantity> <g:payment_accepted>Google Checkout</g:payment_accepted> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Checks</g:payment_accepted> <g:payment_accepted>Cashiers Checks</g:payment_accepted> <g:payment_accepted>Money Orders</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item> <? } ?> </channel> </rss> </xml> Quote Link to comment https://forums.phpfreaks.com/topic/107264-solved-removing-html-formated-markups-from-the-contents-of-a-field/ Share on other sites More sharing options...
jaxdevil Posted May 26, 2008 Author Share Posted May 26, 2008 Well I figured it out. Here is the fixed code below if anyone else ever needs it: <?php mysql_connect('localhost','xxx','xxx'); mysql_select_db('xxx') or die(mysql_error()); ?> <? header("Content-Type: application/rss+xml"); ?> <? echo "<?";?>xml version="1.0" encoding="UTF-8"<? echo "?>";?> <rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link> <?php $sql = "SELECT * FROM products WHERE `active`='Yes' ORDER BY `cats` LIMIT 5" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); $cat = end($cats); $description = $row['description']; $details = $row['details']; $description = strip_tags($description); $details = strip_tags($details); ?> <item><title><?=$row['man']?> <?=$row['mod']?> <?=$row['name']?></title> <g:brand><?=$row['mod']?></g:brand> <g:condition>new</g:condition> <g:description><?=$description?> <?=$details?></g:description> <g:model_number><?=$row['mod']?></g:model_number> <g:id><?=$row['mod']?></g:id> <g:image_link><?=$row['img_url']?></g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=<?=$row['mod']?></g:link> <g:mpn><?=$row['mod']?></g:mpn> <g:price><?=$row['price']?></g:price> <g:product_type><?=$cat?></g:product_type> <g:upc><?=$row['upc']?></g:upc> <g:quantity>1000</g:quantity> <g:payment_notes>Google Checkout</g:payment_notes> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item> <? } ?> </channel> </rss> </xml> Quote Link to comment https://forums.phpfreaks.com/topic/107264-solved-removing-html-formated-markups-from-the-contents-of-a-field/#findComment-550013 Share on other sites More sharing options...
sasa Posted May 26, 2008 Share Posted May 26, 2008 <?php $row['description'] = '<blah blah>one<two></two>two'; echo strip_tags($row['description']); // or //echo preg_replace('/<[^>]*>/',' ',$row['description']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/107264-solved-removing-html-formated-markups-from-the-contents-of-a-field/#findComment-550015 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.