help condensing regular expressions
| From: | Tom Rogers | Date: | Fri, 05 Apr 2002 20:10:54 +0000 |
| Subject: | help condensing regular expressions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-91790@lists.php.net to get a copy of this message | ||
Hi
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.
like IMG src=<?echo $relative_root?>images/logo.png
Regular expressions leave me cold but I have come up with the following monster which works
$relative_root = preg_replace("<\/[[:alnum:]]+>","../", preg_replace("</[[:alnum:]]+$>","",strtok($PHP_SELF,".")));
Anybody have a better solution?
Thanks for any help.
Tom