Extract a substring between two characters in a string PHP

前端 未结 10 1502
逝去的感伤
逝去的感伤 2020-12-02 22:38

Is there a PHP function that can extract a phrase between 2 different characters in a string? Something like substr();

Example:

$String          


        
10条回答
  •  被撕碎了的回忆
    2020-12-02 23:00

    use this code

    $input = "[modid=256]";
    preg_match('~=(.*?)]~', $input, $output);
    echo $output[1]; // 256
    

    working example http://codepad.viper-7.com/0eD2ns

提交回复
热议问题