本文介紹了從 PHP 中的字符串中提取 Twitter 標(biāo)簽的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我需要一些關(guān)于 twitter hashtag 的幫助,我需要在 PHP 中提取某個(gè) hashtag 作為字符串變量.直到現(xiàn)在我有這個(gè)
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 轉(zhuǎn)換為鏈接
but this just transforms hashtag_string into link
推薦答案
使用 preg_match()
識(shí)別散列并將其捕獲到變量中,如下所示:
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'
演示
這篇關(guān)于從 PHP 中的字符串中提取 Twitter 標(biāo)簽的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!