从字符串获取主题标签,并进入meta关键字和标签 [英] Get hashtag from string and get into meta keywords and tags
本文介绍了从字符串获取主题标签,并进入meta关键字和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一种博客共享链接.基本上,对于每个链接,我将从帖子字符串中提取主题标签,并将其放入元标签和关键字中.
I'm creating a kind of a blog sharing link. Basically, for each link i would extract hashtag from post string and put it into a meta tags and keywords.
所以,字符串通常是这样的
So, string normally is like this
#helloworld #test #video #youtube Bon Iver are the best daily surprise :D
现在,我如何仅获取主题标签并将其插入这样的字符串中?
Now, how can i get only hashtags and insert into a string like this ?
$hashtags = helloworld,test,video,youtube
然后在元标记中插入井号
And after insert hashtags in meta tag
<meta name="keywords" content="<? echo $hashtags ?>" >
<meta name="tags" content="<? echo $hashtags ?>">
实际上,我使用此脚本来删除#"并放入,"
Actually i used this script to remove "#" and put ","
$hashclear = preg_replace('/#([A-Za-z0-9]+)/', '$1,', $post);
我如何获得这些?有什么想法吗?
How can i get these ? Any ideas ?
推荐答案
您的意思是这样的吗:
$str = '#helloworld #test #video #youtube Bon Iver are the best daily surprise :D';
preg_match_all('/#([^\s]+)/', $str, $matches);
$hashtags = implode(',', $matches[1]);
var_dump($hashtags);
这篇关于从字符串获取主题标签,并进入meta关键字和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文