php - Regex hash and colons -
i want use regular expression filter substrings string eg: hello world #level:basic #lang:java:php #...
i trying produce array structure this:
array ( [0]=> hello world [1]=> array ( [0]=> level [1]=> basic ) [2]=> array ( [0]=> lang [1]=> java [2]=> php ) )
i have tried preg_match("/(.*)#(.*)[:(.*)]*/", $input_line, $output_array);
and have got is:
array ( [0] => hello world #level:basic #lang:java:php [1] => hello world #level:basic [2] => lang:java:php )
in case have apply regex few times indexes , apply regex filter colon out. question is: possible create better regex in 1 go? regex be? thanks
you can use :
$array = explode("#", "hello world #level:basic #lang:java:php"); foreach($array $k => &$v) { $v = strpos($v, ":") === false ? $v : explode(":", $v); } print_r($array);
Comments
Post a Comment