0

hi guys, i need your help..any help would be appreciated...

im currently exploding a $url and i need to explode the every 3 array from my first explode..


$content = explode ($url)
result
array[1]
array[2]
array[3]// need to explode
array[4]
array[5]
array[6]//need to explode
array[7]
array[8]
array[9]//need to explode
array[n]

i dont know how to do that in a loop because the array result in 40+
so i need to explode the every next 3 array..

sorry for my bad english,, guys i really need your help,
thanks


Mike

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Mongooseman
0

If I understand what you're asking, try using a for loop like this:

for($i = 0; $i < count($array); ++$i)
{
if($i % 3 == 0)
explode($array);
}

The $i % 3 will return the remainder of $i divided by 3, and the remainder will be 0 every third element. I wasn't exactly sure if this is what you were trying to do; let me know if it helps.

0

What exactly are you trying to get out of the url? Perhaps there is a more efficient way to obtain it. Can you post and example url?

0

If I understand what you're asking, try using a for loop like this:

for($i = 0; $i < count($array); ++$i)
{
if($i % 3 == 0)
explode($array);
}

The $i % 3 will return the remainder of $i divided by 3, and the remainder will be 0 every third element. I wasn't exactly sure if this is what you were trying to do; let me know if it helps.

thanks man,
your code save me...
but i did a little revise
$a = 0;
$ii = 14;
while($a<=$ii)
{
$a++;
$m = 3;
$s = $m*$a;
$cntry = explode ("<br>",$url[$s]);

but i have a new problem..
i got what i want but there are some parts of the url that does not match to the array i look for..
here's the code
if($count<=2)
{
$street = "Street address not available";
$city = $cntry[0];
$country1 = $cntry[1];
$country2 = explode ("</td>",$country1);
}
elseif($count <=3)
{
$street = $cntry[0];
$city = $cntry[1];
$country1 = $cntry[2];
$country2 = explode ("</td>",$country1);
}
elseif($count>=7)
{
$street = $cntry[0];
$city = $cntry[1];
$country1 = $cntry[2];
$country2 = explode ("</td>",$country1);
}
else
{
$street = $cntry[0]." ".$cntry[1];
$city = $cntry[2];
$country1 = $cntry[3];
$country2 = explode ("</td>",$country1);
}
$sql = "INSERT INTO banco (SWIFT_BIC,Name,Street,City,Country) VALUES('".$swift[0]."','".$bname[0]."','".$street."','".$city."','".$country2[0]."')";
mysql_query($sql,$con);


my problem was the country.. the variable $cntry is an address, i explode it by <br>.and it work..
example of address
DOUGLAS STREET ,//this to street
PORT MORESBY /// this to city
PAPUA NEW GUINEA //and this to country

but heres the problem
sometimes the addresss
contain CITY AND COUNTRY ONLY which the array change..
sometimes the addresss
contain street AND COUNTRY ONLY which the array change..

how can i get the correct array of country and city in that situation?

sorry for my bad english...

thank you in advance...

0

The easiest way would be to force the input to $cntry to be regular. Is it put in via a form? If so, it would be better to separate street, city, and country into different fields on the form. If the data is created some other way, you could add a <br /> where the country should be, even if it's not there. If you don't have any control over how the data is created, it could be a problem. Without some regular way to differentiate between fields in a string, you almost have to do it manually because a computer lacks the 'intelligence' to know whether "Port Moresby" is a city, country, or street from the context. You could keep a database of all cities, countries, and streets and compare each field with the database, but creating the database would be nontrivial, and it still wouldn't help in situations where alternate spellings or misspellings occur.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.