Jump to content

Echo a Variable to Keyword Meta tag


heaton

Recommended Posts

Hello Every one
 
 
Please see my code

<?php
include ("includes/config.php");
$afurl = $_SERVER['REQUEST_URI'];
$afurl = preg_replace('/\/+/', '', $afurl);
$afurl = preg_replace('/\;+/', '', $afurl);
$afurl = preg_replace('/\&+/', '', $afurl);
$afurl = preg_replace('/\#+/', '', $afurl);
$afurl = preg_replace('/\|+/', '', $afurl);
$afurl = preg_replace('/\@+/', '', $afurl);
$afurl = preg_replace('/\%5B+/', '', $afurl);
$afurl = preg_replace('/\%5D+/', '', $afurl);
$afurl = preg_replace('/\%27+/', '', $afurl);
$afurl = preg_replace('/\%C2+/', '', $afurl);
$afurl = preg_replace('/\%BB+/', '', $afurl);
$afurl = preg_replace('/quot+/', '', $afurl);
$afurl = preg_replace('/\%E2+/', '', $afurl);
$afurl = preg_replace('/\%80+/', '', $afurl);
$afurl = preg_replace('/\%93+/', '', $afurl);
$afurl = preg_replace('/\$+/', 'c', $afurl);
$afurl = preg_replace('/\"+/', '', $afurl);
$afurl = preg_replace('/\?+/', '', $afurl);
$afurl = preg_replace('/\.html+/', '', $afurl);
$afurl = preg_replace('/\-+/', ' ', $afurl);
$queryArray = explode(" ", $afurl);
for ($i=0; $i< count($queryArray); $i++) {
$keyworddd = mysql_real_escape_string($queryArray[$i]).",";
echo $keyworddd;
}
?>

I Want Set $keyworddd at here:

 

    <meta name="keywords" content="$keyworddd">

 

 

Can anyone tell me how to do this please?

Link to comment
https://forums.phpfreaks.com/topic/292008-echo-a-variable-to-keyword-meta-tag/
Share on other sites

You could assign the keywords to an array and then use implode() to add them to the <meta> tag.

<?php
//...
$keyworddd = array();
for ($i=0; $i< count($queryArray); $i++) {
    $keyworddd[] = htmlspecialchars($queryArray[$i]);
}
echo '<meta name="keywords" content="' . implode(', ', $keyworddd) . '">';
?>
 
Side note: is there a reason you are using mysql_real_escape_string()? That function is for escaping stings that you plan to use in a query. To escape strings being displayed to the screen, you would use something like htmlspecialchars() or htmlentities()

 

You could assign the keywords to an array and then use implode() to add them to the <meta> tag.

<?php
//...
$keyworddd = array();
for ($i=0; $i< count($queryArray); $i++) {
    $keyworddd[] = htmlspecialchars($queryArray[$i]);
}
echo '<meta name="keywords" content="' . implode(', ', $keyworddd) . '">';
?>
 
Side note: is there a reason you are using mysql_real_escape_string()? That function is for escaping stings that you plan to use in a query. To escape strings being displayed to the screen, you would use something like htmlspecialchars() or htmlentities()

 

 

 

Hi cyberRobot

 

Thank you . it help me alot :wub:

 

jcbones , thank you too

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.