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? Quote Link to comment Share on other sites More sharing options...
Solution cyberRobot Posted October 23, 2014 Solution 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() Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.