Forum Moderators: coopster
# ABSOLUTE PATH
define('ABS', substr(dirname(__FILE__),0,strlen(dirname(__FILE__))-strlen((basename(dirname(__FILE__))))));
# RELATIVE PATH
define('REL', str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace('\\','/',PATH)));
... i don't know much about regular expressions, is there a way to optimize this constants?
If your code is working and working well without performance issues there is usually not much to be concerned about. However, in this case we might be able to help optimize a bit, who knows ;)
First, you have a CONSTANT named PATH. What is in PATH? Also, the two CONSTANTS you are defining, ABS and REL -- Absolute and Relative to what, the system root or the DocumentRoot?
# ABSOLUTE PATH
define('ABS', substr(dirname(__FILE__),0,strlen(dirname(__FILE__))-strlen((basename(dirname(__FILE__))))));
# RELATIVE PATH
define('REL', str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace('\\','/',ABS)));
REL resolves through ABS, and ABS is directly related to the current docuement root, in this example is:
c:\mywebsite\index.php
And REL resolves:
[localhost...]
But i need a way to optimize those str_replacements with a preg_replace. how?