Connecting Tech Pros Worldwide Forums | Help | Site Map

Explode

Newbie
 
Join Date: Apr 2007
Posts: 2
#1: Apr 12 '07
Hey guys,

I have something like this :

Bank1

Bank2

Bank3

and the list goes on till Bank139.

If I have a string that contains the name of all the banks but including the Empty Lines between them, how do i remove the lines and contain only the name of the banks. For eg : The string now contains : array("bank1", "", "bank2", "", "bank3", ""); , how do i make it array("bank1", "bank2", "bank3");
??? Please help guys...its urgent :(

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#2: Apr 12 '07

re: Explode


Quote:
The string now contains : array("bank1", "", "bank2", "", "bank3", "");
This is an array not a string. When editing or deleted array elements I prefer the C style FOR loop rather the C# FOREACH which is problematic. [PHP]$size = sizeof($bankarray);
for($c=0;$c<$size,$c++){
if(empty($bankarray[$c]))
unset($bankarray[$c]);
}[/PHP]
Newbie
 
Join Date: Apr 2007
Posts: 2
#3: Apr 12 '07

re: Explode


hi,

there's some problem with the snippet u have written on the line :

for($c..........

can u tell me wht is it ?
exoskeleton's Avatar
Member
 
Join Date: Sep 2006
Posts: 104
#4: Apr 13 '07

re: Explode


i think just brackets needed in if statement

[PHP]$size = sizeof($bankarray);
for($c=0;$c<$size,$c++){
if(empty($bankarray[$c])) {
unset($bankarray[$c]);
}
} [/PHP]
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#5: Apr 13 '07

re: Explode


Expand|Select|Wrap|Line Numbers
  1. for($c=0;$c<$size,$c++){
I have used a comma instead of a semi-colon.
[PHP]for($c=0;$c<$size;$c++){[/PHP]
exoskeleton's Avatar
Member
 
Join Date: Sep 2006
Posts: 104
#6: Apr 14 '07

re: Explode


Quote:

Originally Posted by code green

Expand|Select|Wrap|Line Numbers
  1. for($c=0;$c<$size,$c++){
I have used a comma instead of a semi-colon.
[PHP]for($c=0;$c<$size;$c++){[/PHP]

:D :) hehe I did not see that...
Reply