Parsing an .htaccess File With PHP

PatientPaws

New Member
I am using the Zend Framework, and I use the \[code\].htaccess\[/code\] for some settings. I am now writing command line scripts for scheduling (e.g. cron). Command line scripts don't look at the \[code\].htaccess\[/code\] file because they're not served up by Apache. I would like to parse the \[code\].htaccess\[/code\] with my script to retrieve some settings. Here are the lines I'm specifically interested in:\[code\]SetEnv APPLICATION_ENV developmentphp_value date.timezone America/New_York\[/code\]I noticed the PEAR File_HtAccess package, but it seems to only address authentication portions of the \[code\].htaccess\[/code\] file.SOLUTION: (with credit due to Bamieater)\[code\]echo\[/code\] statements for debug output, removed from working code.\[code\]$htaccess = file(realpath(dirname(__FILE__)) . '/.htaccess');echo '<pre>';foreach ($htaccess as $line) { if (preg_match('/^\s*SetEnv\s+APPLICATION_ENV\s+(.*?)\s*$/', trim($line), $matches)) { defined('APPLICATION_ENV') || define('APPLICATION_ENV', $matches[1]); echo APPLICATION_ENV . PHP_EOL; } elseif (preg_match('/^\s*php_(?:admin_)?value\s+date\.timezone\s+(.*?)\s*$/', $line, $matches)) { date_default_timezone_set($matches[1]); echo date_default_timezone_get() . PHP_EOL; }}echo '</pre>';\[/code\]
 
Back
Top