Created
August 29, 2011 22:29
-
-
Save ruthlessfish/1179591 to your computer and use it in GitHub Desktop.
crude script to update base_url and index_page in CodeIgniter config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$base_url = 'http://localhost'; | |
$index_page = ''; | |
$find = array(); | |
$rep = array(); | |
if(php_sapi_name() == 'cli') | |
{ | |
$contents = file_get_contents('config.php'); | |
if(preg_match('/\$config\[\'base_url\'\]\s=\s\'(.*)\'/', $contents, $match)) | |
{ | |
if(empty($match[1])) | |
{ | |
$match[1] = "''"; | |
$base_url = "'$base_url'"; | |
} | |
$res = str_replace($match[1], $base_url, $match[0]); | |
$find[] = $match[0]; | |
$rep[] = $res; | |
} | |
if(preg_match('/\$config\[\'index_page\'\]\s=\s\'(.*)\'/', $contents, $match)) | |
{ | |
if(empty($match[1])) | |
{ | |
$match[1] = "''"; | |
$index_page = "'$index_page'"; | |
} | |
$res = str_replace($match[1], $index_page, $match[0]); | |
$find[] = $match[0]; | |
$rep[] = $res; | |
} | |
file_put_contents('config.php', str_replace($find, $rep, $contents)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a first round proof of concept. will be reworking this.