PHP : How to count the number of URLs, hashtags and user_mentions in a Twitter tweet -
i want count number of urls , #hashtags posted in tweet. using php scan twitter feeds. possible count of urls , #hashtags posted in twitter tweet ?
how ?
edit:
i tried code
preg_match_all('/#\s*\w/i', $tweet, $matches); var_dump( $matches );
output:
array(1) { //count1 [0]=> array(1) { [0]=> string(12) "#goodmorning" } } array(1) { //count2 [0]=> array(1) { [0]=> string(11) "#helloworld" } } array(1) { //count3 [0]=> array(0) { } } array(1) { //count4 [0]=> array(0) { } }
expected output:
number of hashtags = 2 number of urls = 3 (if any)
thank help
based off of answer in retrieve hashtags tweet in php function, adding counting of ouput.
$tweet = "this has #hashtag #badhash-tag , #goodhash_tag"; preg_match_all("/(#\w+)/", $tweet, $matches); count($matches[0]);
Comments
Post a Comment