Read and Write to php file
I am looking for a method to write the values of some variable to a PHP file.
Ok let me explain by example:
I have a normal PHP website and want to add WordPress as a blog to it.
I use the same theme as of my WordPress for the other site too, removing the WordPress tags and replacing them with my other application’s tags. So here the Div IDs and Class names remain the same. Also I share the same CSS & JS files as WordPress.
I want to control the width of my sidebars and some other parameters from the WordPress Theme control panel. The process I think should be…
get value for 'sidebar_a' and say inputs is '150px' get value for 'main_body' and say inputs is '550px' get value for 'sidebar_b' and say inputs is '200px' get value for ‘site_name’ and say the input comes from the WordPress tag get value for ‘footer ‘and say again the value comes from the WordPress footer.
Now I need a small script which will write these values in a PHP file like:
$sidebar_a = '100' $main_body = '550' $sidebar_b = '200' $sitename = ‘XYZ Corporation’ $footer = ‘Copyright XYZ corporation'
or better create some database tables in MySQL and write to it.
I would then want to call this file in my application 2 using
Please feel free to suggest, if there is a better way.
IMPORTANT: Every time these parameters are changed in WordPress, these values must be updated with the new values.
$data = array( 'sidebar_a' => $sidebar_a, 'main_body' => $main_body, 'sidebar_b' => $sidebar_b, 'sitename' => $sitename, 'footer' => $footer ); $data = serialize($data); file_put_contents('file.txt', $data);
$data = file_get_contents('file.txt'); $data = unserialize($data); extract($data);
See serialize and extract