Thanks Kevin- yeah I guess I'll have to chop up the string. David
----- Original Message ----- From: "Kevin Stone" <[EMAIL PROTECTED]> To: "David Yee" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, January 03, 2002 12:30 PM Subject: Re: [PHP] find all the numeric positions of a character that appears in a string multiple times > SPLIT to the rescue! Split tears up your string into lists (arrays) which > you can cycle through and extract normaly. So this is going to look like > hell but here we go... > > <? > $str = "<a href=http://foo.bar><b>test</b></a>"; > > $str_list1 = split ('<', $str); > // Note: $str_list1 now == array ("a href=http://foo.bar>", "b>test", "/b>", > "/a>") > $a = 0; > for ($i=0; $i<count($str_list1); $i++) > { > $str_list2 = split ('>', $str_list1[$i]); > for ($j=0; $j<count($str_list2); $j++) > { > if (empty($str_list2[$j])) > { > next; // skip blank indexes... > } > else > { > $str_list[$a] = $str_list2[$j]; // populate results list... > $a++; > } > } > } > > // print it out... > for ($i=0; $i<count($str_list); $i++) > { > echo "$str_list[$i]<br>"; > } > ?> > > > ... GAH! I second thought there's got to be a better way of doing this! > Anyway hope it helps some. > > -Kevin > > > > Hi guys. What is the best way to find all the numeric positions of a > > character that appears in a string multiple times? E.g. let's say I have > > the following string: > > > > $str = "<a href=http://foo.bar><b>test</b></a>"; > > > > And I want to parse the string and extract everything between <>. Now if > > the string only had a single occurrence of "<" and ">" I can use strpos() > > and substr() to extract it, but how do I do it for multiple occurrences? > I > > suppose I can keep chopping up the string to do this but I'm not sure if > > that's the best way. Thanks. > > > > David > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]