Get all matches from string that start with and end, using php

后端 未结 2 758
悲&欢浪女
悲&欢浪女 2021-01-08 01:10

How would I use PHP to extract everything in between [startstring] and [endstring] from this string:

[startstring]hello = guys[ends         


        
2条回答
  •  逝去的感伤
    2021-01-08 02:01

    preg_match_all('/\[startstring\](.*?)\[endstring\]/s', $input, $matches);
    echo implode(' ', $matches);
    

    preg_match_all('/\[startstring\](.*?)\=(.*?)\[endstring\]/s', $input, $matches);
    for ($i = 0; $i < count($matches[1]); $i++) {
        $key = $matches[1][$i];
        $value = $matches[2][$i];
        $$key = $value;
    }
    

提交回复
热议问题