php - Extract keyword that Word Pattern -
i have string.
hi {$user_name} test msg {$user1,$user2,$user3}
i want extract {$word}
string. have tried use str_replace
not working.
short solution preg_mach_all
function:
$str = 'hi {$user_name} test msg {$user1,$user2,$user3}'; preg_match_all('/\s*(\{\$[^\{\}]+\})+\s*/iue', $str, $matches); echo "<pre>"; var_dump($matches[1]); // output: array(2) { [0]=> string(12) "{$user_name}" [1]=> string(22) "{$user1,$user2,$user3}" }
Comments
Post a Comment