php正则表达式匹配tweet中的话题
/**
* @desc 匹配话题
* array
'#PHP#' => string 'PHP' (length=3)
'#正则表达式#' => string '正则表达式' (length=15)
'#a#' => string 'a' (length=1)
'#A#' => string 'A' (length=1)
* */
function matchTopic($text = '') {
$return = null;
if (preg_match_all ( '/\#([^\#|.]+)\#/', $text, $topics )) {
if (isset ( $topics [0] ) && isset ( $topics [1] )) {
$return = array ();
foreach ( $topics [1] as $key => $topic ) {
$return [$topic] = $topics [0] [$key];
}
}
}
return $return;
}
- cfanwzl's blog
- 添加新评论
- 450 次点击