本文介紹了從 PHP 中的字符串中提取 Twitter 標簽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要一些關于 twitter hashtag 的幫助,我需要在 PHP 中提取某個 hashtag 作為字符串變量.直到現在我有這個
I need some help with twitter hashtag, I need to extract a certain hashtag as string variable in PHP. Until now I have this
$hash = preg_replace ("/#(\w+)/", "<a , $tweet_text);
但這只是將 hashtag_string 轉換為鏈接
but this just transforms hashtag_string into link
推薦答案
使用 preg_match()
識別散列并將其捕獲到變量中,如下所示:
Use preg_match()
to identify the hash and capture it to a variable, like so:
$string = 'Tweet #hashtag';
preg_match("/#(\w+)/", $string, $matches);
$hash = $matches[1];
var_dump( $hash); // Outputs 'hashtag'
演示
這篇關于從 PHP 中的字符串中提取 Twitter 標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!