所以我使用preg_match来获取#up之后的任何文本,直到字符串中的空格为止.但是,如果字符串中有多个场合,它将只返回第一个.这就是我到目前为止所拥有的
$text = '#demo1 #demo2 some text #blah2';
$check_hash = preg_match("/([#][a-zA-Z-0-9]+)/", $text, $hashtweet);
foreach ($hashtweet as $ht){
echo $ht;
}
Run Code Online (Sandbox Code Playgroud)
的echo $ht;输出#demo1#demo1时,它应该输出的与#在前面的单词的所有3.任何帮助是极大的赞赏.
Fra*_*nes 18
你想用preg_match_all.
例:
<?php
$text = '#demo1 #demo2 some text #blah2';
$check_hash = preg_match_all("/([#][a-zA-Z-0-9]+)/", $text, $hashtweet);
foreach ($hashtweet[1] as $ht){
echo $ht;
}
Run Code Online (Sandbox Code Playgroud)