Jump to content

HTML code in my PHP


randall

Recommended Posts

I am sure this has been answered in the past and is a valid question, I have searched high and low for this solution on and off for a few months. Any help would be greatly appreciated...

 

Please note: if you respond, keep it simple-ish - I code but not advanced.

 

First, take a look at the HTML source on the following page... Specificity the meta description.

http://boormanarchery.com/test.php?route=common/home&information_id=5

 

<META NAME="Description" CONTENT="Terms & Conditions - <p>

Terms & Conditions</p>

">

 

HTML code is pulled into the description field... I want to strip every single piece of HTML.

 

Here is my HTML / PHP code...

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
$con = mysql_connect("localhost","username","password");
mysql_select_db("MyDatabase",$con);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Get ID From URL
$id = (isset($_GET['information_id']) ? $_GET['information_id'] : 0);
$routeid = (isset($_GET['route']) ? $_GET['route'] : 0);

// Return Product Code and Select
$details = "SELECT * FROM information_description WHERE information_id=($id)";

$SQ_query = mysql_query($details);
$detail = mysql_fetch_array($SQ_query);

$metatitle = $detail['title'];
$longdescription = $detail['description'];

$metadescription=substr($longdescription, 0, 150);
$metakeywords=substr($longdescription, 0, 150); 

mysql_close($con);
?>

<html>
<head>
<title>Boorman Archery: <?php echo "$metatitle"; ?></title>
<META NAME="Description" CONTENT="<?php echo "$metatitle"; ?> - <?php echo html_entity_decode($metadescription, ENT_QUOTES, "ISO-8859-1"); ?>">
<META NAME="Keywords" CONTENT="<?php echo "$metatitle"; ?> , archery, boorman, bows, arrows">
<META NAME="author" content="Randall Wright">
<META NAME="copyright" content="Boorman Archery">
<meta http-equiv="pragma" content="no-cache">
<META NAME="language" content="en-us">
<META NAME="rating" content="General">
<META name="robots" content="index,follow">
<META NAME="revisit-after" content="7 Days">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

</body>
</html>

 

Link to comment
Share on other sites

I will do a Paypal donate if u can fix this!!  Please!

 

Thank you so much Pikachu2000, but after playing with your code and many other examples over the weekend, I can not get it right. I think I need a bit more of a hand with this...

 

I am begging, can someone please... The following example is just one of the MANY ways I have tried to remove all the unwanted junk. All I want left is readable text with absalutly no HTML, CSS, or strange things like...  <p>  As you can see below,....ARRRRRG!

 

I have tried strip_tags, htmlspecialchars, preg_replace, strrpos, str_replace, htmlentities, and I don't know how many more... I have tried to use arrays that others have built, and I think everything else I could find through a weekend of solid searching and testing.

 

<?php
$desc = $metadescription;
$match = array(
    "/<ref(?:[^\/&]|&(?!gt;))*\/>/is",
    "/<ref[^\/]*>(.*?)<\/ref>/s",);
$desc = preg_replace($match,'',$desc);
echo $desc;
?>

 

Output:

 

<p style="text-align: center; ">

<strong>The Staff of Boorman Archery</strong></p>

<p style="text-align: 

 

 

Another Example:

 


function strip_html_tags( $uncleandescription )
{
    $uncleandescription = preg_replace(
        array(
          // Remove invisible content
            '@<head[^>]*?>.*?</head>@siu',
            '@<style[^>]*?>.*?</style>@siu',
            '@<script[^>]*?.*?</script>@siu',
            '@<object[^>]*?.*?</object>@siu',
            '@<embed[^>]*?.*?</embed>@siu',
            '@<applet[^>]*?.*?</applet>@siu',
            '@<noframes[^>]*?.*?</noframes>@siu',
            '@<noscript[^>]*?.*?</noscript>@siu',
            '@<noembed[^>]*?.*?</noembed>@siu',
          // Add line breaks before and after blocks
            '@</?((address)|(blockquote)|(center)|(del))@iu',
            '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
            '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
            '@</?((table)|(th)|(td)|(caption))@iu',
            '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
            '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
            '@</?((frameset)|(frame)|(iframe))@iu',
        ),
        array(
            ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',"$0", "$0", "$0", "$0", "$0", "$0","$0", "$0",), $uncleandescription );
  
    // you can exclude some html tags here, in this case B and A tags        
    return strip_tags( $uncleandescription , ' ' );
}

$description=substr($uncleandescription, 0, 150);

?>
<?php
echo strip_tags("Hello <b><i>world!</i></b>","<b>");
?>


<html>
<head>
<title>Boorman Archery: <?php echo strip_tags($metatitle); ?></title>
<META NAME="Description" CONTENT="<?php echo strip_tags($metatitle); ?> - <?php echo strip_tags($description); ?>">
<META NAME="Keywords" CONTENT="<?php echo strip_tags($metatitle); ?>, archery, boorman, bows, arrows">
<META NAME="author" content="Randall Wright">
<META NAME="copyright" content="Boorman Archery">
<meta http-equiv="pragma" content="no-cache">
<META NAME="language" content="en-us">
<META NAME="rating" content="General">
<META name="robots" content="index,follow">
<META NAME="revisit-after" content="7 Days">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 

Output:


Note the:  <p>


Hello <b>world!</b>

<html>
<head>
<title>Boorman Archery: </title>
<META NAME="Description" CONTENT=" - <p>

Your bow requires minimal maintenance, but does need some care and attention to keep it in perfect order. Following these simple steps sho">
<META NAME="Keywords" CONTENT=", archery, boorman, bows, arrows">
<META NAME="author" content="Randall Wright">
<META NAME="copyright" content="Boorman Archery">
<meta http-equiv="pragma" content="no-cache">
<META NAME="language" content="en-us">
<META NAME="rating" content="General">
<META name="robots" content="index,follow">
<META NAME="revisit-after" content="7 Days">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>



</body>
</html>


Link to comment
Share on other sites

The problem is that <strong> isn't recognized as a tag. < and > are html entities until decoded with html_entity_decode.

 

$meta = '<p style="text-align: center; ">

   <strong>The Staff of Boorman Archery</strong></p>

<p style="text-align: ';

echo trim(strip_tags(html_entity_decode($meta)));

// RETURNS "The Staff of Boorman Archery"

Link to comment
Share on other sites

 

Here is my latest...

 

I am still getting some of the bits like   and some javascript is being pulled in as well... I now need to get rid of that pesky javascript as well. :) Below in the Description...

 

I am also wondering if anyone would be cleaning this up for me? I am sure there is a way to streamline the code. Thanks!!!  - Unbanned?? I was never banned.

 

<META NAME="Description" CONTENT="Field Tournaments - var popupWindow = null;

function centeredPopup(url,winName,w,h,scroll){

LeftPosition = (screen.width">

 

<?php

$con = mysql_connect("############","#######","###########!");
mysql_select_db("boorman_open",$con);

// Get Product Code From URL

$informationid = (isset($_GET['information_id']) ? $_GET['information_id'] : 0);
$homepageid='25437';
$routeid = (isset($_GET['route']) ? $_GET['route'] : 0);
$productid = intval($_GET['product_id']);
$categoryid = (isset($_GET['product/category']) ? $_GET['product/category'] : 0);
$pathid = (isset($_GET['path']) ? $_GET['path'] : 0);
$filterid = (isset($_GET['filter_name']) ? $_GET['filter_name'] : 0);
$companyname = "Boorman Archery";

if ($routeid == "common/home")
{
$get = "SELECT * FROM setting WHERE setting_id='25430'";
$SQ_query = mysql_query($get);
$fetch = mysql_fetch_array($SQ_query);

$metatitle = $companyname;
$longdescription = $fetch['value'];
$metadescription=substr($longdescription, 0, 150);
$metakeywords=substr($longdescription, 0, 150);
}
elseif ($routeid == "information/information") 
{ 
$get = "SELECT * FROM information_description WHERE information_id=($informationid)";
$SQ_query = mysql_query($get);
$fetch = mysql_fetch_array($SQ_query);

$metatitle = $fetch['title'];
$longdescription = $fetch['description'];
$metadescription=substr($longdescription, 0, 150);
$metakeywords=substr($longdescription, 0, 150);
}
elseif ($productid = $productid) 
{ 
$get = "SELECT * FROM product_description WHERE product_id=($productid)";
$SQ_query = mysql_query($get);
$fetch = mysql_fetch_array($SQ_query);

$metatags = $fetch['name'];
$longdescription = $fetch['description'];
$metadescription=substr($longdescription, 0, 150);
$metakeywords=substr($longdescription, 0, 150);
$metatitle=substr($metatags, 0, 50);
} 
elseif ($pathid = $pathid) 
{ 
$get = "SELECT * FROM `category_description` WHERE `category_id` = ($pathid)";
$SQ_query = mysql_query($get);
$fetch = mysql_fetch_array($SQ_query);

$metatitle = $fetch['name'];
$longdescription = $fetch['description'];
$metadescription=substr($longdescription, 0, 150);
$metakeywords=substr($longdescription, 0, 150);
}
elseif ($filterid = $filterid) 
{ 
$metatitle = $filterid;
$metadescription = $filterid;
$metakeywords = $filterid;
}
else 
{
$details = "SELECT * FROM product_description WHERE product_id=($productid)";
echo " ";
}

mysql_close($con);
?>
<title><?php echo $companyname; ?>: <?php echo trim(strip_tags(html_entity_decode($metatitle))); ?></title>
<META NAME="Description" CONTENT="<?php echo trim(strip_tags(html_entity_decode($metatitle))); ?> - <?php echo trim(strip_tags(html_entity_decode($metadescription))); ?>">
<META NAME="Keywords" CONTENT="<?php echo trim(strip_tags(html_entity_decode($metatitle))); ?>, archery, bow, arrows, compound bow, archer, bowhunting, field archery, target archery <?php echo trim(strip_tags(html_entity_decode($metakeywords))); ?>">
<META NAME="author" content="Randall Wright">
<META NAME="copyright" content="Company">
<meta http-equiv="pragma" content="no-cache">
<META NAME="language" content="en-us">
<META NAME="rating" content="General">
<META name="robots" content="index,follow">
<META NAME="revisit-after" content="7 Days">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Link to comment
Share on other sites

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.