I'm building a string dynamically. The result is that it may start with a dash (-), a space or a letter. I need to remove the first two, if they occur. The following code simulates the problem. If ran as is, it outputs XB - CX, which is correct (the X's are to show there aren't any spaces). But it seems unnecessary and overly complicated to use three trims in a row. The $array can come from a number of sources so while I could probably condition the string there, that would cause more code than the three trims. Can anyone see a better way to do this?
Hmm, I had tried something like that, although with ltrim. Maybe I'm confused about the charlist argument. I tried
ltrim($str, "' '..'-')
which seems to be the way the manual says to enter multiple characters. Is that not correct? Isn't the ' -' in yours just searching for that combination (space and dash)? I can see the code works but would like to understand the correct use of the command.
What it means by "With .. you can specify a range of characters." is a range of characters such as 1 to 9, or A to C, etc (1..9, or A..C, etc). For the basic characters you wish stripped, simply list one right after another, such as " -" or " \t_" etc. Nothing to seperate them, PHP will look at the characters one by one unless it sees .. to designate a range.