Page 1 of 1

Problem of slash

Posted: Tue Sep 16, 2008 11:52 am
by aliahsan81
Hi all,

I m realy thank full to this forum it gave me really help in time.I am facing a problem i have an array in which a trailing slash is appearing,So i need to remove that slash below is the out put.and this array is dynamic it mean next time when i run the code i don't know where slash will appear.can any one help me with this.For reference see index 4

sudo php write.php
Array
(
[0] => /var/www/html
[1] => /test/abc/xyx
[2] => /var/www/wsite/c-clientx1.awpdc.com/htdoc
[3] => /var/www/wsite/c-clientx1.awpdc.com/htdoc2
[4] => /var/www/wsite/www.mytriptrace.com/htdoc/
[5] => /var/www/wsite/www.mytriptrace.com/htdoc
)

Re: Problem of slash

Posted: Tue Sep 16, 2008 12:06 pm
by ahowell

Code: Select all

<?php
 
foreach ($array as $key => $value) {
    $array[$key] = ltrim('/', $value);   // remove char from left side of string
    $array[$key] = rtrim('/', $value);   // remove char from right side of string
    $array[$key] = trim('/', $value);    // remove char from left & right side of string
}

Re: Problem of slash

Posted: Tue Sep 16, 2008 1:36 pm
by aliahsan81
Thxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Alot.Its worked