开发者

php string separate function

开发者 https://www.devze.com 2023-02-20 18:30 出处:网络
In my project a file contains content like &lbl1=Mount Olympus - 24\" long x 48\" wide - Oil on canvas&prc1=725&so开发者_开发知识库ld1=&

In my project a file contains content like

&lbl1=Mount Olympus - 24" long x 48" wide - Oil on canvas&prc1=725&so开发者_开发知识库ld1=&

&lbl2=Edgartown Marsh 1 - oil on canvas (matted unframed) size: 5 ½" x 5 ½"&prc2=425&sold2=SOLD&

and so and so..

I need to display Mount Olympus - 24" long x 48" wide - Oil on canvas,725 and so and so

is it possible?

i have first read the content from that file and then tried to explode with & ie $arrayNewLine=explode("&",$newLine);

But it's not my result.

Des anyone know this?


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


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);


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

精彩评论

暂无评论...
验证码 换一张
取 消