need help with trim please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

need help with trim please

Post by kholloi »

Hi I am trying to remove whitespace from array ellements.

I came up with this:

Code: Select all

$file = file("/etc/sysconfig/network/ifcfg-$if");

//Clean whitespace from array ellements

for($i = 0; $i <= 8; $i++)
&#123;
trim($file&#1111;$i]);
&#125;

echo var_dump($file);

But the whitespace remains. Here is the output of var_dump():
array(9) {
[0]=>
string(19) "BOOTPROTO='static'
"
[1]=>
string(26) "BROADCAST='192.168.1.255'
"
[2]=>
string(23) "IPADDR='192.168.1.153'
"
[3]=>
string(7) "MTU=''
"
[4]=>
string(24) "NETMASK='255.255.255.0'
"
[5]=>
string(22) "NETWORK='192.168.1.0'
"
[6]=>
string(17) "REMOTE_IPADDR=''
"
[7]=>
string(19) "STARTMODE='onboot'
"
[8]=>
string(26) "UNIQUE='QXTf.TgVqGjtNpC0'
"
}
Are there any obvious mistakes?

THanks
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

yep. use this instead:

Code: Select all

//....
$file[$i] = trim($file[$i]);
//....
Post Reply