Page 1 of 1

ltrim() ?

Posted: Wed Jan 06, 2010 10:59 am
by jcafaro10
I'm trying to use the ltrim function but getting an error.

Here's my code:
$line = ltrim($line,"../music/");
I just want to remove "../music/" from some text.

Getting this warning:

Code: Select all

Warning: ltrim() [function.ltrim]: Invalid '..'-range, no character to the left of '..' in C:\xampp\htdocs\music3.php on line 3

Re: ltrim() ?

Posted: Wed Jan 06, 2010 11:16 am
by manohoo

Re: ltrim() ?

Posted: Wed Jan 06, 2010 11:18 am
by jcafaro10
actually thats not true, the link you sent specifies that it will remove characters as well. The ltrim function does remove what I need it to but it throws that warning, I'm not sure what it means or why its being thrown.

Re: ltrim() ?

Posted: Wed Jan 06, 2010 11:18 am
by AbraCadaver
The second parameter is a character list and the .. means a range, such as a..z would strip characters from a to z. Assuming that you just want the filename, I would use basename().

Re: ltrim() ?

Posted: Wed Jan 06, 2010 11:58 am
by jcafaro10
I'll look into basename(). How can I actually remove ".." then?

Re: ltrim() ?

Posted: Wed Jan 06, 2010 12:05 pm
by AbraCadaver
jcafaro10 wrote:I'll look into basename(). How can I actually remove ".." then?
Several ways, substr_replace(), str_replace()... But if you want the filename portion of a path then that's what basename() is meant for.