本文介紹了在 PHP 函數中從推文中檢索所有主題標簽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想使用 PHP 函數從推文中檢索所有主題標簽.
I want to retrieve all hashtags from a tweet using a PHP function.
我知道有人在這里問過類似的問題,但沒有提示如何在 PHP 中實現這一點.由于我對正則表達式不是很熟悉,不知道如何編寫一個函數來返回推文中所有主題標簽的數組.
I know someone asked a similar question here, but there is no hint how exactly to implement this in PHP. Since I'm not very familiar with regular expressions, don't know how to write a function that returns an array of all hashtags in a tweet.
那么我該怎么做,使用以下正則表達式:
So how do I do this, using the following regular expression:
#S*w
推薦答案
$tweet = "this has a #hashtag a #badhash-tag and a #goodhash_tag";
preg_match_all("/(#w+)/", $tweet, $matches);
var_dump( $matches );
*破折號是標簽的非法字符,允許使用下劃線.
*Dashes are illegal chars for hashtags, underscores are allowed.
這篇關于在 PHP 函數中從推文中檢索所有主題標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!