The "solve" string generates an array based on a custom rule output
String generation arrays are output based on custom rules
According to function Split_array ("Baidu #http://www.baidu.com/\n Baidu #http://www.baidu.com/\n", "\n|#", "{0}");
Required output
Baidu
Baidu
How do you write this function?
------Solution--------------------
Write
PHP code like this
Split_array ("Baidu #http://www.baidu.com/\n Baidu #http://www.baidu.com/\n", "\n|#", "{0}"); function Split_array ($STR, $ Pattern, $template) { $cnt = Substr_count ($template, ' {');//The number of alternate locations in the statistics template $tmp = preg_split ('/'. $pattern. ' /', $STR,-1, preg_split_no_empty); Cut data by rule $m = count ($tmp)% $cnt; if ($m) $tmp = array_slice ($tmp, 0,-$m); Remove Redundant data $tmp = Array_chunk ($tmp, $cnt);//Group data $r = Array (); foreach ($tmp as $m) { $t = $template; foreach ($m as $i = + $v) { $t = Str_replace ("{{$i}}", $v, $t); } $r [] = $t; } echo Join ('
', $r);}