UPWORK/ODESK guru: Tips and Tricks for clients

skype: odesk.by / upwork.link , email: info@odesk.by/upwork.link

php: save PHP variables to a text file

without comments

Writing $text to a file:


$text = "Anything";
$var_str = var_export($text, true);
$var = "<?php\n\n\$text = $var_str;\n\n?>";
file_put_contents('filename.php', __FILE__ . ":". __LINE__ . "\t" . date(DATE_RFC2822) . "\n", FILE_APPEND | LOCK_EX);
file_put_contents('filename.php', $var, FILE_APPEND | LOCK_EX);

Retrieving it again:

include 'filename.php';
echo $text;

Written by spectre

January 30th, 2016 at 3:38 pm

Posted in Php