note 118921 added to function.preg-replace

From: Date: Sun, 28 Feb 2016 18:11:24 +0000
Subject: note 118921 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-205062@lists.php.net to get a copy of this message
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; } ---- Server IP: 72.52.91.14 Probable Submitter: 24.4.60.233 ---- Manual Page -- http://php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/118921 Del: integrated -- https://master.php.net/note/delete/118921/integrated Del: useless -- https://master.php.net/note/delete/118921/useless Del: bad code -- https://master.php.net/note/delete/118921/bad+code Del: spam -- https://master.php.net/note/delete/118921/spam Del: non-english -- https://master.php.net/note/delete/118921/non-english Del: in docs -- https://master.php.net/note/delete/118921/in+docs Del: other reasons-- https://master.php.net/note/delete/118921 Reject -- https://master.php.net/note/reject/118921 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205062) next »