PHP PHP - 1 year ago 91
PHP Question

how to implode this pattern to array?

i want implode this txt pattern to Multidimensional Arrays and echo array into table

My pattern :<


i want echo this pattern like this (dont show website address)

Group1: john-jack-jorge

Group2: Ivan-Dan-Ted

Answer Source

Try this:

$str = "group1&john,]jack,]jorge,^group2&Ivan,]Dan,]Ted,^";

$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/>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download