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


i've been searching lot cannot find similar problem. i've found link don't think answered question.

let have string

$my_string = "i [id]123[/id] , [id]456[id]"; 

i want number between [id][/id]. have function string between.

function get_string_between($string, $start, $end){     $string = ' ' . $string;     $ini = strpos($string, $start);     if ($ini == 0) return '';     $ini += strlen($start);     $len = strpos($string, $end, $ini) - $ini;     return substr($string, $ini, $len); }  $fullstring = 'i [id]123[/id] , [id]456[id]'; $parsed = get_string_between($fullstring, '[id]', '[/id]'); 

but function returns first string found on $fullstring. maybe can 123,456 or in array form array('123','456'). stuck this.

you can use preg_match_all function of php along following regex

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

like as

$my_string = "i [id]123[/id] , [id]456[/id]"; preg_match_all("~\[id\](.*?)\[\/id\]~",$my_string,$m); print_r($m[1]); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -