note 71284 deleted from function.explode by colder

From: Date: Tue, 21 Nov 2006 09:27:22 +0000
Subject: note 71284 deleted from function.explode by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119921@lists.php.net to get a copy of this message
Note Submitter: erelsgl dot NOSPAM at cs dot technion dot ac dot il Reason: bad code ---- If you want to split a path into name+extension, explode(".",$path,1) will not work, because if path contains more than one dot, then all dots will be included in the extension. Here is the solution I found (it returns the last dot with the extension): <?php function split_name_and_extension($path) { if (preg_match('/(.+)(\..*)$/', $path, $matches)) { array_shift($matches); // return $matches[1], $matches[2] return $matches; } else { return array($path, ""); } } ?>

« previous php.notes (#119921) next »