php - replace specific string pattern to html -
for stock-market chat want replace every specific string pattern html code. illustration if type "b $goog 780" want string replaced with:
buy <a href="/stocks/goog">$goog</a> @ 780
how can specific task preg_replace?
$cmd='b $goog 780'; if(preg_match('/^([bs])\s+?\$(\w+?)\s+?(.+)$/i',$cmd,$res)) { switch($res[1]) { case 'b': $cmd='buy';break; case 's': $cmd='sell';break; } $link=$cmd.' <a href="/stocks/'.$res[2].'">'.$res[2].'</a> @ '.$res[3]; echo $link; }
php html string replace preg-replace
No comments:
Post a Comment