Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

PHP strings tip

PHP Tip: You can access characters within a PHP string using the index of the caracter in curly braces after the variable name. For example, $string{0} returns the first character, $string{3} returns the fourth character and $string{strlen($string)-1} returns the last character. You can assign to individual characters of a string in the same way, so $string{0} = strtoupper($string{0}); will convert the first character of a string to upper case. For more tips on working with strings see the PHP manual and Zend’s useful strings tutorial.

This is PHP strings tip by Simon Willison, posted on 7th August 2002.

View blog reactions

Next: Yup this site is for real

Previous: Smarty 2.30

2 comments

  1. Of course you can also use the ucfirst function for that example: string ucfirst ( string str) Returns a string with the first character of str capitalized, if that character is alphabetic.

    Jan! - 11th August 2002 18:47 - #

  2. help me with this

    dhector830@yahoo.com - 19th December 2003 15:52 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2002/08/07/phpStringsTip

A django site