Capturing content between square bracket tags in PHP -


i want put content bracket defined tags in text below , put of them array, attempts in php , preg_match function has been failed many times. should in php using preg_match function?

$string="[restab title="name"]john o'brian[/restab][restab title="telephone"]+15254636544[/restab][restab title="address"]newyork, wallstreet ave, no 5[/restab]" 

you might looking this:

preg_match_all('/\[[^]]+\]([^[]+)\[\/[^]]+\]/is', $string, $matches); 

this gives following results:

array(2) {   [0]=>   array(3) {     [0]=>     string(42) "[restab title="name"]john o'brian[/restab]"     [1]=>     string(47) "[restab title="telephone"]+15254636544[/restab]"     [2]=>     string(62) "[restab title="address"]newyork, wallstreet ave, no 5[/restab]"   }   [1]=>   array(3) {     [0]=>     string(12) "john o'brian"     [1]=>     string(12) "+15254636544"     [2]=>     string(29) "newyork, wallstreet ave, no 5"   } } 

you can add more brackets capture text within square brackets.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -