Re: Re: help condensing regular expressions

From: Date: Sat, 06 Apr 2002 07:37:13 +0000
Subject: Re: Re: help condensing regular expressions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-91846@lists.php.net to get a copy of this message
Thanks Chris Thats what I was after :) At the top of each page I now do $reltoroot = preg_replace("|/[^/]+|", "../", dirname($_SERVER['PHP_SELF'])); ini_set ("include_path",ini_get("include_path").":".$reltoroot."../include"); which takes care of the include path I use the path translated info for pages that are sym linked across virtual domains such as admin pages. Thanks again Tom At 03:49 PM 6/04/2002, Chris Adams wrote:
In article <5.1.0.14.0.20020406055420.032b6bd8@crux.kwikin.com>, Tom Rogers wrote: I am trying to calculate how far into a directory structure I am so that I can include images and include files without having to hard code them. I need to turn $PHP_SELF which could be /admin/emails/index.php into ../../ which I can then use to get to any directory from root. Here's a more compact regexp: preg_replace("|/[^/]+|", "../", dirname($_SERVER['PHP_SELF'])); dirname() returns only the directory part of a filename (e.g. "/~chris" from "/~chris/myfile.php"). Using | instead of the usual / to delimit the regular expression just saves a bit of typing. (Note that for includes, you'd be better off setting include_path in php.ini or .htaccess - that avoids the need to worry about where the files are physically located) If you need the local file path and you're using Apache, the PATH_TRANSLATED variable can tell you where your files are: $current_dir = dirname($PATH_TRANSLATED) . "/"; This could be used to construct absolute paths internally - I use it in my photo gallery code when creating thumbnails & such with convert. Using it with DOCUMENT_ROOT can help if you need to construct things like directory listings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#91846) next »