1
如何用JavaScript代替Twitter风格#hashtags?为#标签解析文本并使用JavaScript代替链接
I.e. this is a #hashtag
应该变成this is a <a href="tag/hashtag">#hashtag</a>
。
对于PHP:Parse text for hashtags and replace with links using php
如何用JavaScript代替Twitter风格#hashtags?为#标签解析文本并使用JavaScript代替链接
I.e. this is a #hashtag
应该变成this is a <a href="tag/hashtag">#hashtag</a>
。
对于PHP:Parse text for hashtags and replace with links using php
t = 'this is a #hashtag'
t.replace(/#(\w+)/g, '<a href="tag/$1">#$1</a>')
给人
this is a <a href="tag/hashtag">#hashtag</a>
1.写的主题标签一个正则表达式。 2.调用替换并替换你想要的任何标签。 3.找出你想要一个像'tag/hashtag]'这样的无效href的原因。 – 2015-10-14 18:40:48
注意''我的#hashtag很酷,请查看mysite.com /#bookmark''这个在Kasper的回答中有分歧 – SmokeyPHP
你应该看看[twitter-text](https://github.com/twitter/ Twitter的文本)。它包含解析国际化主题标签的代码,而不仅仅是ASCII。 – nhahtdh