php string separate function

前端 未结 3 682
轮回少年
轮回少年 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:16

    You can do with file_get_contents and parse_str()

        $data=file_get_contents('finename.ext');
    
        parse_str($data,$parsed_data);
    
        print_r($parsed_data);
    
    0 讨论(0)
  • 2021-01-25 18:25

    That looks like a URL query string. Try decoding it?

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题