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

后端 未结 2 759
悲&欢浪女
悲&欢浪女 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 01:58

    Try with preg_match_all:

    preg_match_all('/\[startstring\](.*?)\[endstring\]/', $input, $matches);
    var_dump($matches);
    
    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题