note 14435 deleted from function.substr by jimw

From: Date: Thu, 20 Dec 2001 23:01:49 +0000
Subject: note 14435 deleted from function.substr by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23528@lists.php.net to get a copy of this message
watch out for this, where $string2 is actually at the end of $string1, and you are trying to remove $string2. ie- $string1 = "testing" . $string2; $newstr = substr ($string1, 0, -strlen($string2)); $newstr will then equal "testing", if (strlen($string2) > 0). but if (strlen($string2) == 0), $newstr will equal "", because -strlen($string2) will be 0. this is probably not what you want. :) i hope that makes some sense, and i hope this solution -could- be helpful. $string1 = "testing" . $string2; $newstr = substr ($string1 . " ", 0, -strlen($string2) - 1); this will always work, because strlen($string2) - 1 will always be <= -1. anyway, if you don't understand what i'm going on about, make sure you read above in the actual manual. i'm too lazy to write it out all again. :)

« previous php.notes (#23528) next »