我希望将这个txt模式内爆到多维数组并将数组回显到表
中我的模式:
<group1&john,www.johnsite.com]jack,www.jacksite.com]jorge,www.jorgesite.com^group2&Ivan,www.ivansite.com]Dan,www.dansite.com]Ted,wwww.tedsite.com^
我希望像这样回复这种模式(不要显示网站地址):
第1组:john-jack-jorge
第2组:Ivan-Dan-Ted
答案 0 :(得分:0)
试试这个:
$str = "group1&john,www.johnsite.com]jack,www.jacksite.com]jorge,www.jorgesite.com^group2&Ivan,www.ivansite.com]Dan,www.dansite.com]Ted,wwww.tedsite.com^";
$str = trim($str, "^");
$groups = explode("^", $str);
foreach($groups as $val){
$group = ucfirst(explode("&", $val)[0]);
$arr = explode("]", explode("&", $val)[1]);
$name = array();
foreach($arr as $v)
$name[] = explode(",", $v)[0];
$name = implode("-", $name);
echo $group.": ".$name."<br/>";
}