开发者

php exploding text in keywords meta tag

I am trying to explode every individual word in my page titles to use as separate keywords. So if I had the page title "This is my web page" then my keywords meta tag would look like this

<meta name="Keywords" content="This, is, my, web, page"> 

I am using this code right here to try to achieve that but this code repeats the keyword meta tag multiple times. I am also trying to use a preg_replace to remove unwanted text. Can anyone help me figure out how I should be doing this?

$tobeOmitted=array('quot');
$keys = explode(" ", preg_replace("/[^a-zA-Z0-9s]/", " ", $row['title']));
foreach( $keys as $key => $value){
if(!in_array($value,$tobeOmitted))
ec开发者_StackOverflow中文版ho "<meta content='$value' name='keywords'";
}

Like I said what I am trying to do is use my page title and explode it into individual words with a comma after each for my keywords meta tag and also use a preg_replace to remove unwanted text. I appreciate any help. Thanks.


You only need one instance of the keyword META tag.

Try this:

$res = preg_replace('/[^a-z0-9\s]/ui', '', $theString);
$arr = preg_split('/\s+/', $res);
echo "<meta content='".implode(',', $arr)."' name='keywords'";


Try the Following code

$val = "";
$tobeOmitted=array('quot');
$keys = explode(" ", preg_replace("/[^a-zA-Z0-9s]/", " ", $row['title']));

foreach( $keys as $key => $value)
{
   if(!in_array($value,$tobeOmitted))
      $val .= ",".$value
}
$val = sub_str($val,1);
echo "<meta content='$val' name='keywords'>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜