note 85477 added to language.types.string

From: Date: Mon, 01 Sep 2008 22:05:20 +0000
Subject: note 85477 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-144059@lists.php.net to get a copy of this message
So you want to get the last character of a string using "String access and modification by character"? Well negative indexes are not allowed so $str[-1] will return an empty string. <?php //Tested using: PHP 5.2.5 $str = 'This is a test.'; $last = $str[-1]; //string(0) "" $realLast = $str[strlen($str)-1]; //string(1) "." $substr = substr($str,-1); //string(1) "." echo '<pre>'; var_dump($last); var_dump($realLast); var_dump($substr); ---- Server IP: 209.41.74.194 Probable Submitter: 66.27.49.42 ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/85477 Del: integrated -- https://master.php.net/note/delete/85477/integrated Del: useless -- https://master.php.net/note/delete/85477/useless Del: bad code -- https://master.php.net/note/delete/85477/bad+code Del: spam -- https://master.php.net/note/delete/85477/spam Del: non-english -- https://master.php.net/note/delete/85477/non-english Del: in docs -- https://master.php.net/note/delete/85477/in+docs Del: other reasons-- https://master.php.net/note/delete/85477 Reject -- https://master.php.net/note/reject/85477 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144059) next »