heaton Posted October 23, 2014 Share Posted October 23, 2014 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 More sharing options...
cyberRobot Posted October 23, 2014 Share Posted October 23, 2014 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 https://forums.phpfreaks.com/topic/292008-echo-a-variable-to-keyword-meta-tag/#findComment-1494464 Share on other sites More sharing options...
jcbones Posted October 23, 2014 Share Posted October 23, 2014 preg_replace() takes an array for patterns also. I'm not sure if it is faster, but it would be worth benchmarking. Link to comment https://forums.phpfreaks.com/topic/292008-echo-a-variable-to-keyword-meta-tag/#findComment-1494470 Share on other sites More sharing options...
heaton Posted October 23, 2014 Author Share Posted October 23, 2014 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 jcbones , thank you too Link to comment https://forums.phpfreaks.com/topic/292008-echo-a-variable-to-keyword-meta-tag/#findComment-1494527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.