PHP get string between tag [Multiple tag in one string]

前端 未结 1 1276
渐次进展
渐次进展 2020-12-18 03:20

I\'ve been searching a lot but i cannot find anything similar to my problem. I\'ve found this link but i don\'t think they really answered the question.

Let say i ha

相关标签:
1条回答
  • 2020-12-18 03:57

    You can simply use preg_match_all function of the PHP along with following regex

    ~\[id\](.*?)\[\/id\]~
    

    like as

    $my_string = "I am with a [id]123[/id] and [id]456[/id]";
    preg_match_all("~\[id\](.*?)\[\/id\]~",$my_string,$m);
    print_r($m[1]);
    
    0 讨论(0)
提交回复
热议问题