• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

从字符串获取主题标签,并进入meta关键字和标签

用户头像
it1352
帮助1

问题说明

我正在创建一种博客共享链接.基本上,对于每个链接,我将从帖子字符串中提取主题标签,并将其放入元标签和关键字中.

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 ?

正确答案

#1

您的意思是这样的吗:

$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);

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcbhefe
系列文章
更多 icon
同类精品
更多 icon
继续加载