Skip to content

Instantly share code, notes, and snippets.

@ruthlessfish
Created August 29, 2011 22:29
Show Gist options
  • Save ruthlessfish/1179591 to your computer and use it in GitHub Desktop.
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
<?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));
}
@ruthlessfish
Copy link
Author

this is a first round proof of concept. will be reworking this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment