RE: split and array logic
| From: | Tim Ward | Date: | Wed, 02 May 2001 08:08:33 +0000 |
| Subject: | RE: split and array logic | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-51105@lists.php.net to get a copy of this message | ||
depends how reliable the format of the string you're splitting is. If they
are all like your examples then ...
foreach ($stuff as $key=>$element)
{ $dummy = explode(" ", $element);
$stuff[$key] = array();
$stuff[$key]["user"] = $dummy[0];
$stuff[$key]["browser"] = $dummy[2];
}
foreach ($stuff as $element)
{ foreach($element as $field=>$value) echo("$field=>$value<br>");
}
... should do it. if the strings are more complicated you'll need to look at
stristr, substr, etc.
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Matthew Luchak [mailto:MLuchak@Kaydara.com]
> Sent: 01 May 2001 19:09
> To: php-general@lists.php.net
> Subject: split and array logic
>
>
>
> I can't quite get the logic to create my own associative arrays:
>
> if:
>
> $stuff[0]="165.33.114.63 anonymous Mozilla/4.0"
> $stuff[1]="213.35.354.93 anonymous Mozilla/4.0"
>
> how do I end up with:
>
> $stuff[0][user]="165.33.114.63"
> $stuff[0][browser]="Mozilla/4.0"
>
> $stuff[1][user]="213.35.354.93"
> $stuff[1][browser]="Mozilla/4.0"
>
> I am hacking away at:
>
> foreach( $stuff as $cFile ) {
>
> list ($user, $junk, $browser) = split (' ', $cFile);
> }
>
>
> and it hurts.....any hints ?
>
> TIA,
>
> ____________________________
> Matthew Luchak
> Webmaster
> Kaydara Inc.
> mluchak@kaydara.com
>
>