Replace PHP variable name inside PHP files
Posted: Sun Jul 22, 2007 10:20 pm
hi,
i would like to change some variable name in my php file, for example $basePath to $myPath. this is my functions
and inside auth.php
so, i want to change require( $basePath . '/sources.php' ); to require( $myPath . '/my-sources.php' );. i can change the filename, no problem with it but not $basePath. the only problem is i cannot change the PHP variable name to something else.
thank you for your help.
i would like to change some variable name in my php file, for example $basePath to $myPath. this is my functions
Code: Select all
function patchFile( $file, $search, $replace ) {
if ( $fp = fopen( $file, 'r' ) ) {
$content = fread( $fp, filesize( $file ) );
fclose($fp);
}
else {
// return error message
}
if( strpos( $content, $value ) === true ) {
//$this->_isPatch = true;
}
// we didn't find it, proceed to patch process
else {
$content = str_replace( $search, $replace, $content );
if( $fp = fopen( $file, 'w' ) ) {
fwrite( $fp, $content, strlen( $content ) );
fclose( $fp );
unset( $content );
echo 'Done!';
} else {
unset( $content );
// return error message
echo 'Error!';
}
}
}
function start() {
$file = "D:/XAMPP/xampp/htdocs/my/tryout/xsecure/administrator/auth.php";
$search = "$basePath";
$replace = "$mypath";
patchFile( $file, $search, $replace );
}Code: Select all
$basePath = dirname( __FILE__ );
require( $basePath . '/sources.php' );
$basePath = dirname( __FILE__ );
require( $basePath . '/config.php' );
/*
other code....
....
....
*/thank you for your help.