php string separate function

前端 未结 3 681
轮回少年
轮回少年 2021-01-25 17:44

In my project a file contains content like

&lbl1=Mount Olympus - 24\" long x 48\" wide - Oil on canvas&prc1=725&sold1=&

&lbl2=Edgartown Mar         


        
3条回答
  •  臣服心动
    2021-01-25 18:34

    The parse_str function is what you're after.

    Alternatively, you could iterate like so:

    $labels = array();
    
    foreach (explode('&', $newLine) as $item) {
        list($name, $value) = explode('=', $item);
        $labels[$name] = $value;
    }
    

    Now you have an indexed array of labels. If you want all of the values as a string, try

    implode(', ', $labels);
    

    Good luck!

提交回复
热议问题