Re: removing chars from string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul Nowosielski <paul@xxxxxxxxxxxxxxxxxxx> wrote:
> If a have a string thats 11 characters long how can I strip off the last
> two characters?

Jay Blanchard <jay.blanchard@xxxxxxxxxxxxxxxxxxxxx> wrote:
> $newString = substr($oldString, 0, 8);
> echo $newString;

substr's third argument is length, not position.  It also accepts
negative values which makes it go from the end, allowing you to do
absolute lengths or relative.

To make a string no more than 9 characters:
  substr($string, 0, 9);

To always remove the last two characters of a string:
  substr($string, 0, -2);

http://php.net/substr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux