note 104624 added to function.dirname

From: Date: Mon, 27 Jun 2011 03:54:14 +0000
Subject: note 104624 added to function.dirname
Groups: php.notes 
Request: Send a blank email to php-notes+get-180973@lists.php.net to get a copy of this message
As usual, to include or require a file, we use this <?php require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'my_file.php'; ?> in rare case, we have current file existing at the root directory, dirname would return C:\ or / , then the line above contains 2 slashes \\ or // To handle this this case, we use rtrim to clear slashes. <?php require rtrim(dirname(__FILE__), '/\\') . DIRECTORY_SEPARATOR . 'my_file.php'; ?> Also, another use of dirname is to get virtual directory (url path), the issue is the same as above, we have to check and process before concatenating strings ---- Server IP: 69.147.83.197 Probable Submitter: 115.73.178.38 ---- Manual Page -- http://www.php.net/manual/en/function.dirname.php Edit -- https://master.php.net/note/edit/104624 Del: integrated -- https://master.php.net/note/delete/104624/integrated Del: useless -- https://master.php.net/note/delete/104624/useless Del: bad code -- https://master.php.net/note/delete/104624/bad+code Del: spam -- https://master.php.net/note/delete/104624/spam Del: non-english -- https://master.php.net/note/delete/104624/non-english Del: in docs -- https://master.php.net/note/delete/104624/in+docs Del: other reasons-- https://master.php.net/note/delete/104624 Reject -- https://master.php.net/note/reject/104624 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180973) next »