从字符串获取主题标签,并进入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
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
使用c++17更新时出现G++编译器警告
it1352 06-18 -
Android微调工具-删除当前选择
it1352 06-20 -
Reaction本机IOS Safari没办法打开页面,因为该地址在有效登录后无效
it1352 06-07 -
复制文件夹/文件而不修改属性?
it1352 07-15