Splitting array problem
Posted: Fri Jul 01, 2005 6:31 am
I seem to be having a weird problem when extracting a text from a file. I have a file that contains text delimited with '::' and "|", this '::' is broken up and then the '|' sub string is broken down into it's various values. Everything goes well except for the odd string seems to get broken down yet again "on three of the entries (No pattern)", between the "|" delimiter is. There are 185 substrings in the file. For example: '36.3463889,6.6091667,0,1, ' would become '36.3463889,6.6091667' and ',0,1, ', anyone any ideas?
I have check the obvious.
For example the 'Illouz|35.7,-0.6166667,0,1, |1|1|134' string below seperates into '35.7,-0.6166667' and ',0,1, ' but the others are fine. 'Illouz' is actually the 84th '::' part of the string.
Thanks
I have check the obvious.
For example the 'Illouz|35.7,-0.6166667,0,1, |1|1|134' string below seperates into '35.7,-0.6166667' and ',0,1, ' but the others are fine. 'Illouz' is actually the 84th '::' part of the string.
Code: Select all
$thestring = "Illouz|35.7,-0.6166667,0,1, |1|1|134::Isly|36.7833333,3.05,0,1, |1|1|134::Faubourg D'el Kantara|36.3694444,6.6211111,0,1, |1|1|134::";
$array = explode("::",$thestring);
$num2 = count($array); // Entry count
$array2 = array();
for ($i = 0 ; $i < $num2 ; $i++) {
$array2 = explode("|",$array[$i]); // Explode the array to get the variables
$num = count($array2);
for ($n = 0 ; $n < $num ; $n++) {
$array3["arg".$n] = $array2[$n];
}
$location_name = str_replace("`","'",$array3['arg0']);
$geo_data = trim($array3['arg1']);
$location_type = trim($array3['arg2']);
//$unused = trim($array3['arg3']); //Unused
$country_id = trim($array3['arg4']);
//Check the values
echo "$country_id : $location_name : $geo_data : $location_type<br />";
}