note 65211 added to function.strstr

From: Date: Thu, 27 Apr 2006 00:16:36 +0000
Subject: note 65211 added to function.strstr
Groups: php.notes 
Request: Send a blank email to php-notes+get-109801@lists.php.net to get a copy of this message
Also in response to: john :: beech :: at :: mkv25 :: dot :: net Trying to use your function to trim the last directory from a path i found out that it doesn't work if a directory has the same name as the subdirectory for example <? function backstr($haystack, $needle) { return substr($haystack, 0, strlen($haystack) - strlen(strstr($haystack,$needle))); } echo backstr('/var/www/site/test/test','/test'); // returns "/var/www/site" // instead of "/var/www/site/test" ?> My version for solving this 'special' problem : <? function back_dir($path){ $go1 = rtrim ($path , '/'); $back_dir = substr ($go1,0,strlen($go1) - strlen(strrchr($go1 , '/'))); return $back_dir . "/"; } ?> ---- Server IP: 62.103.148.26 Probable Submitter: 62.74.144.103 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strstr.php Edit -- http://master.php.net/note/edit/65211 Del: integrated -- http://master.php.net/note/delete/65211/integrated Del: useless -- http://master.php.net/note/delete/65211/useless Del: bad code -- http://master.php.net/note/delete/65211/bad+code Del: spam -- http://master.php.net/note/delete/65211/spam Del: non-english -- http://master.php.net/note/delete/65211/non-english Del: in docs -- http://master.php.net/note/delete/65211/in+docs Del: other reasons-- http://master.php.net/note/delete/65211 Reject -- http://master.php.net/note/reject/65211 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#109801) next »