AoNo Posted January 14, 2012 Share Posted January 14, 2012 can someone explain how this works? im a newbie just need help // setting up the web root and server root for // this shopping cart application $thisFile = str_replace('\\', '/', __FILE__); $docRoot = $_SERVER['DOCUMENT_ROOT']; $webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile); $srvRoot = str_replace('library/config.php', '', $thisFile); define('WEB_ROOT', $webRoot); define('SRV_ROOT', $srvRoot); Link to comment https://forums.phpfreaks.com/topic/254987-help/ Share on other sites More sharing options...
gizmola Posted January 14, 2012 Share Posted January 14, 2012 The goal of this code is to create 2 constants to be used for including files from a known location, and for setting up url's. In php you create constants with the define() function. PHP has the $_SERVER superglobal that gets variables from apache and makes them available to php. This is being used to help figure out the web root. the __FILE__ is a magic php constant that provides the complete path and filename of the file in which it is called. It is often used by a configuration script in a a known relative location, so that a basepath variable does not have to manually configured by the users of the scripts. str_replace is being used to do some manipulation of the strings involved. You should take a look at the manual pages on php.net for hte functions that you don't understand. You can also echo or var_dump variables in the script to help you understand what value they hold when the script executes. Link to comment https://forums.phpfreaks.com/topic/254987-help/#findComment-1307485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.