Reply to Re: [PHP] removing chars from string

Your name:

Reply:


Posted by Kevin L'Huillier on 06/27/05 18:44

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

Jay Blanchard <jay.blanchard@niicommunications.com> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация