note 14435 added to function.substr.php

From: Date: Tue, 31 Jul 2001 12:57:29 +0000
Subject: note 14435 added to function.substr.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16098@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. :) http://www.php.net/manual/en/function.substr.php

« previous php.notes (#16098) next »