Jump to content

Echo a Variable to Keyword Meta tag


heaton
 Share

Go to solution Solved by cyberRobot,

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
Share on other sites

  • Solution

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()
Link to comment
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()

 

 

 

Hi cyberRobot

 

Thank you . it help me alot :wub:

 

jcbones , thank you too

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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