note 118921 deleted from function.preg-replace by cmb
| From: | cmb@php.net | Date: | Sun, 22 Sep 2019 08:00:29 +0000 |
| Subject: | note 118921 deleted from function.preg-replace by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212304@lists.php.net to get a copy of this message | ||
Note Submitter: smcbride at msn dot com
----
A nice and easy way to merge file path strings without worrying about if the path is suffixed with /
or the file is prefixed with / is to use preg_replace. There may be a function to get the
endpoints, but this will also fixup any garbage in the middle as well.
Also...the previous post left out an important character to escape if you want to search for it ...
/ (slash).
function mergepath($rootpath, $suffixpath){
$completepath = $rootpath . "/" . $suffixpath;
$completepath = preg_replace('/\/+/', '/',, $completepath);
return $completepath;
}