Extracting Twitter hashtag from string in PHP

前端 未结 7 1187
离开以前
离开以前 2020-12-18 11:19

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         


        
7条回答
  •  忘掉有多难
    2020-12-18 11:47

    As i understand you are saying that in text/pargraph/post you want to show tag with hash sign(#) like this:- #tag and in url you want to remove # sign because the string after # is not sended to server in request so i have edited your code and try out this:-

    $string="www.funnenjoy.com is best #SocialNetworking #website";    
    $text=preg_replace('/#(\\w+)/','$0',$string);
    echo $text; // output will be www.funnenjoy.com is best #SocialNetworking #website
    

提交回复
热议问题