I am trying to remove just the first character from a string. I know that chop() will chop off the last character, but is there a function that removes the first character? I am trying to change "/location" to "location" using the fastest possible method since the length of location is n.

    No, [man]chop[/man] is an alias for [man]rtrim[/man] and will not chop off the last character. It will however remove any spaces, new lines and a few other things that is in the end of the string.

    If you are looking for a function that will do the same in the beginning of the string look at [man]ltrim[/man], or if you want both look at [man]trim[/man].

    If you are after a function that will cut the first character off a string no matter what character it is you could use the following:

    $str = "abcde";
    $cut_str = substr($str, 1);
    

    You find more information in the [man]substr[/man] part of the manual. You might want to add other checks as well, for example you might want to check that the string is set [man]isset[/man] and that it is not [man]empty[/man].

      Write a Reply...