21,886
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head><body>
<h1>Get Hashtags</h1>
<?php
$subject = "捣乱的字符#tags #tagging #中文 #csdn论坛 #使用google google #143 #中1 #1中";
$pattern = '%((?:\A|(?<=\s))(?:#|@)(\w|(\p{L}\p{M}?))+\b)|(\[(#|@)[^\]]+\])%u';
preg_match_all($pattern, $subject, $matches);
$words = $matches[0];
print_r($words);
?>
</body>
</html>
$subject = "#tags#tag #中文已经#能支持了";
$subject = "捣乱的字符#tags #tagging #中文 #csdn论坛 #使用google google #143 #中1 #1中";
$pattern = '/#.+(?:[\s]{1}|$)/Um';
preg_match_all($pattern, $subject, $matches);
print_r($matches[0]);
Array ( [0] => #tagging [1] => #csdn [2] => #使用google [3] => #143 [4] => #中1 [5] => #1 )
Array ( [0] => #tagging [1] => #中文 [2] => #csdn论坛 [3] => #使用google [4] => #143 [5] => #中1 [6] => #1中 )