I am using the following command to print an array of data to a file saved as .php so i can use include to grab the array later.
$toFile = '$Data = '. var_export($DataArray,true).'; ';
file_put_contents( $filename.'.php', "<?php ".$toFile." ?>");
It is printed to the file formatted to make it easy to read but it ends up taking up a lot more space on the disk due to spaces and newline and such. Is there an easy way to remove the formatting so it take up less space. I thought of using str_replace which would work for new lines but not spaces due to the data might have spacing in it.
<?php $Data = array (
'Info' =>
array (
'value1' => 'text here',
'value2' => 'text here',
'value3' => '$2,500 to $9,999',
), ....
to something like this
<?php $Data = array('Info'=>array('value1'=>'text here','value2'=>'text here','value3'=>'$2,500 to $9,999'),...
Thanks
EDIT: Is there a preg_replace pattern i can use to remove unwanted spaces ONLY outside of quotes?