Quoting Aaron Heimlich <[EMAIL PROTECTED]>:

That's awesome Aaron. That is pretty powerful.

> On 11/22/06, Christopher Jordan <[EMAIL PROTECTED]> wrote:
> >
> >
> > Er, you are aware that you can reference strings as arrays in PHP, or if
> > needed convert a string to a real array in one line, right?
> >
> > for ($i=0; $i < strlen($string); ++$i) {
> >  print $string[$i] . "\n";
> > }
> > foreach (explode($string) as $char) {
> >  print $char . "\n";
> > }
> >
> >    How do you tell PHP what the list delimiter is?
> >
> 
> Actually Christopher mixed up the argument order for explode()[1]. It's:
> 
> explode("delimiter", $string);
> 
> Actually, explode isn't even the right function to use for what he's
> demonstrating. The str_split function[2] is actually what you want.
> 
> foreach(str_split($string) as $char) {
>     print $char . "\n";
> }
> 
> 
> [1] http://us3.php.net/manual/en/function.explode.php
> [2] http://us3.php.net/manual/en/function.str-split.php
> 
> <cfset str = "a,b,c,d|d,e,f,g*h,i,j,k|l,m,n,o">
> >
> > I can then turn around and get the first element based on the asterisk
> > being the delimiter and then treat the result (a,b,c,d|d,e,f,g) as a new
> > list who's delimiter is the pipe and then end up with last list whose
> > delimiter is the comma.
> >
> > <cfloop index="i" from ="1" to="#ListLen(str, '*')#">
> >     <cfset str2 = ListGetAt(str, i, "*")>
> >     <cfloop index="n" from="1" to="#ListLen(str2, '|')#">
> >           <cfset str3 = ListGetAt(str2, n, "*")>
> >           <cfloop index="j" from="1" to="#ListLen(str3)#">
> >                 <!--- do some stuff with the innermost elements of the
> > list --->
> >           </cfloop>
> >     </cfloop>
> > </cfloop>
> >
> > Can you do that in php?
> >
> 
> $str = "a,b,c,d|d,e,f,g*h,i,j,k|l,m,n,o";
> 
> foreach(explode("*", $str) as $half) {
>     foreach(explode("|", $half) as $quarter) {
>         foreach(explode(",", $quarter) as $letter) {
>             // Do something unbelivably cool
>         }
>     }
> }
> 




_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to