요즘 대세인 샵과 멘션정보를 홈페이지나 SNS 볼수 있는데..
해당 #,@만 추출하는 정규식 함수입니다.
<!--//
function tag_string($string){
$re = '/(#[0-9a-zA-Z가-힣ㄱ-ㅎ]*)/ui';
$str = $string;
preg_match_all($re, $str, $matches);
$change = array();
foreach ( $matches[0] as $s ) $change[$s] = "<a href=''><strong style='color:#6699CC;'>".$s."</strong></a>";
echo strtr($str,$change).'';
}
function nickname_tag_string($string){
$re = '/(@[0-9a-zA-Z가-힣ㄱ-ㅎ]*)/ui';
$str = $string;
preg_match_all($re, $str, $matches);
$change = array();
foreach ( $matches[0] as $s ) $change[$s] = "<strong style='color:#aaa;'>".$s."</strong>";
echo strtr($str,$change).'';
}
//-->
해당 #,@만 추출하는 정규식 함수입니다.
<!--//
function tag_string($string){
$re = '/(#[0-9a-zA-Z가-힣ㄱ-ㅎ]*)/ui';
$str = $string;
preg_match_all($re, $str, $matches);
$change = array();
foreach ( $matches[0] as $s ) $change[$s] = "<a href=''><strong style='color:#6699CC;'>".$s."</strong></a>";
echo strtr($str,$change).'';
}
function nickname_tag_string($string){
$re = '/(@[0-9a-zA-Z가-힣ㄱ-ㅎ]*)/ui';
$str = $string;
preg_match_all($re, $str, $matches);
$change = array();
foreach ( $matches[0] as $s ) $change[$s] = "<strong style='color:#aaa;'>".$s."</strong>";
echo strtr($str,$change).'';
}
//-->