0
I wonder if someone has or can get me some script to change contents of a PHP file in specific lines without changing the others, it may be fopen, fwrite and fclose.
Actually want, along with data captured in form
, alter some define
.
The input[name='url_site']
would change the line define('WFOX_SITE_URL', 'http://127.0.0.1/wfox');
The input[name='theme_site']
would change the line define('WFOX_SITE_THEME', WFOX_SITE_DIR . '/v1');
The input[name='name_site']
would change the line define('WFOX_SITE_NAME', 'Meu Projeto');
Full script [define_log.php]
:
error_reporting(0);
session_start();
$user_id = $_SESSION['user_id'];
date_default_timezone_set('America/Fortaleza');
ini_set('default_charset', 'utf-8');
define('WFOX_BASE_DIR', __DIR__);
define('WFOX_SITE_DIR', WFOX_BASE_DIR . '/wfox-content');
define('WFOX_ADMIN_DIR', WFOX_BASE_DIR . '/wfox-admin');
define('WFOX_SITE_URL', 'http://127.0.0.1/wfox');
define('WFOX_SITE_ADM', WFOX_SITE_URL . '/wfox-admin');
define('WFOX_SITE_THEME', WFOX_SITE_DIR . '/v1');
define('WFOX_SITE_NAME', 'Meu Projeto');
include( WFOX_ADMIN_DIR . '/database/conn.php');
include( WFOX_ADMIN_DIR . '/api/wfox_bd_api.php');
include( WFOX_ADMIN_DIR . '/api/wfox_bd_post.php');
include( WFOX_ADMIN_DIR . '/api/wfox_bd_user.php');
include( WFOX_ADMIN_DIR . '/api/wfox_bd_upload.php');
include( WFOX_ADMIN_DIR . '/api/wfox_stats_chart.php');
Just an idea: file_get_contents , explode PHP_EOL, will have an array with all lines, foreach going through this array and checking if there are the names of the constants that you want to modify. If it exists, rewrite the line by mounting a new constant define with the new value. Merge a string with everything and save the file.
– Antonio Alexandre