Jump to content

[SOLVED] Removing HTML formated markups from the contents of a field


Recommended Posts

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>

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.