Page 1 of 1

problems using explode

Posted: Thu Nov 20, 2003 9:58 pm
by infolock
Well, today I've been doing a little reading on explode and have gotten pretty close to doing what I am trying to do.

What it is that i'm trying to do, is take these strings :
Mozilla/4.0_(compatible;_MSIE_6.0;_Windows_98;_Q312461;_FunWebP )
and explode them into variable names based on their browser.

so, here is what i've done so far :

Code: Select all

<?php

$Mozilla = array('Netscape/7%','Mozilla/6%','Mozilla/5%','Mozilla/4%','NSPlayer/4%','NSPlayer/7%','NSPlayer/9%');

for($i=0; $i<8; $i++)
{
	$sql = "SELECT UserAgent, count(UserAgent) FROM log WHERE (UserAgent LIKE '".$Mozilla[$i]."') Group by UserAgent HAVING count(UserAgent) > 0";
	$result = mysql_query($sql) or die(MySQL_Error());
	$row = mysql_fetch_assoc($result);
	$Moz_Found[$i] = $row['count(UserAgent)'];
	$temp = explode(".",$row['UserAgent']);

##############################
##  Since I couldn't get this to work, i tried ##
##  seeing at least what the array table list ##
## looked like.   The results are at the end ##
##############################
	print_r($temp[0]);
	echo '<br />';
}

?>


the results, sadly, came back like this :

Array ( [0] => )
Array ( [0] => )
Array ( [0] => )
Array ( [0] => Mozilla/4 [1] => 0_(compatible;_MSIE_6 [2] => 0;_Windows_98;_Q312461;_FunWebP )
Array ( [0] => NSPlayer/4 [1] => 1 [2] => 0 [3] => 3854 )
Array ( [0] => NSPlayer/7 [1] => 1 [2] => 0 [3] => 3055 )
Array ( [0] => NSPlayer/9 [1] => 0 [2] => 0 [3] => 2980 )
Array ( [0] => )

see, what I need to do is assign each of the found array[0]'s that actually contain values to a seperate #, instead of just using 0 for all of them.. get what i mean?

in other words, when I use the echo command to view this array like this :

Code: Select all

<?php

//.....

echo $temp[0];

?>

i get the following result :
Mozilla/4NSPlayer/4NSPlayer/7NSPlayer/9
instead of just getting Mozilla/4, making it impossible for me to use this...

any help would be seriously appreciated. 8O

Posted: Fri Nov 21, 2003 1:38 am
by infolock
any thoughts on this at all?

Posted: Fri Nov 21, 2003 4:20 am
by infolock
I guess i'll just go with doing it manually by using 4 sql s tatements and getting the results one at a time then since that works. just was wondering if the for loop worked. oh well :P i'll figure out how to do it this way oen of these days :)

Posted: Fri Nov 21, 2003 6:24 am
by m3mn0n
I think javascript is best for this. It returns variables that are easier to parse.