sandis_m Posted September 18, 2011 Report Share Posted September 18, 2011 Vajag izdabūt vērtību, kas ir starp [] $teksts = "kaut kaads teksts [1]"; $count = preg_match('/[(.*?)]/', $teksts, $match); if ($count === FALSE){ echo('not found\n'); }else { echo print_r($match); } Vai man vienīgajam izvada: Array ( ) 1 Es nekādīgi netieku pie tās vērtības 1 $match[0],$match[1],$match[2].... Quote Link to comment Share on other sites More sharing options...
marrtins Posted September 18, 2011 Report Share Posted September 18, 2011 (edited) preg_match_all('/[([^]]*)]/imsU'); Edited September 18, 2011 by marrtins Quote Link to comment Share on other sites More sharing options...
marcis Posted September 19, 2011 Report Share Posted September 19, 2011 (edited) marrtins whut? <? $matches = array(); $str = 'kaut kaads teksts [1] kaut kaads teksts [2] kaut kaads teksts [3]'; preg_match_all('/\[(.*)\]/U', $str, $matches); print_r($matches); /* Array ( [0] => Array ( [0] => [1] [1] => [2] [2] => [3] ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) */ ?> Edited September 19, 2011 by marcis Quote Link to comment Share on other sites More sharing options...
marrtins Posted September 19, 2011 Report Share Posted September 19, 2011 (edited) marrtins whut? Te kaut-kas gļuko - noņēma slashus, jābūt tā: $str = 'aaa [11] ccc [22][33] bb[44[] nana'; preg_match_all('/\[([^\]\[]*)\]/imsU', $str, $matches); print_r($matches); Edited September 19, 2011 by marrtins Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.