note 44698 deleted from function.substr by tomsommer

From: Date: Mon, 16 Aug 2004 03:08:51 +0000
Subject: note 44698 deleted from function.substr by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74749@lists.php.net to get a copy of this message
Note Submitter: bisqwit at iki dot fi ---- I believe this sample code is useful for many like me who have trouble remembering how substr works with negative numbers. <?php $input = "abcdefg"; echo substr($input, 0, 2), "\n"; /* Outputs "ab" */ echo substr($input, 0, -2), "\n"; /* Outputs "abcde" */ echo substr($input, 2), "\n"; /* Outputs "cdefg" */ echo substr($input, -2), "\n"; /* Outputs "fg" */ echo substr($input, 2, 1), "\n"; /* Outputs "c" */ echo substr($input, -2, 1), "\n"; /* Outputs "f" */ echo "'", $input[2], "'\n"; /* Outputs "'c'" */ echo "'", $input[-2], "'\n"; /* Outputs "''" */ ?> (Ps: The preview function seems to eat my backslashes. Hope the actual posting doesn't. In case it did anyway, imagine that every "n" has a backslash.)

« previous php.notes (#74749) next »