Page 1 of 1

split() ?

Posted: Tue Jun 14, 2005 6:11 pm
by Pineriver
How would I do this ?

Take this string and return everything between [ ] as an array output

Code: Select all

$rr=&quote;thisscritjajsjї OUT1 ]ajdamsda;sjo;tkpdkї OUT2 ]sdfmjsї OUT3 ]dfjlsd&quote;;

$a = some function

echo '<pre>';
print_r($a);

    &#1111;0] =>  &#1111; OUT1 ]
    &#1111;1] =>  &#1111; OUT2 ]
    &#1111;2] =>  &#1111; OUT3 ]
Thanks

Posted: Tue Jun 14, 2005 6:25 pm
by Chris Corbyn

Code: Select all

$rr="thisscritjajsj[ OUT1 ]ajdamsda;sjo;tkpdk[ OUT2 ]sdfmjs[ OUT3 ]dfjlsd";
 
//$a = some function
preg_match_all('/\[[^\]]*\]/', $rr, $a);
 
echo '<pre>';
print_r($a);

ok

Posted: Tue Jun 14, 2005 8:24 pm
by Pineriver
ok thats wonderful, now to take it up to the next step.

$rr="thisscritjajsjD OUT1 aviajdamsda;sjo;tkpdkC OUT2 avisdfmjsI OUT3 avidfjlsd";

finds a single letter thats bewteen A and X for the start, and "avi" for the ending, I know the basics of how this syntax works and tried something like

Code: Select all

preg_match_all('/\&#1111;^&#1111;A-X]]*\avi/', $rr, $a);
this returned null, also might anyone know of some good samples of how this syntax is preformed?
Thanks

Posted: Tue Jun 14, 2005 9:43 pm
by Ambush Commander
I'm not exactly sure what you're looking for, but try:

Code: Select all

$rr="thisscritjajsjD[ OUT1 ]aviamsda;sjo;tkpdC[ OUT2 ]avisdfmjsI[ OUT3 ]avilsd";
preg_match_all('/[A-Z]\[[^\]]*\]avi/', $rr, $a);
echo '<pre>';
print_r($a);