Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reversing the PHP file() function

I converted a .php file to an array using the file() function.
Now I modified the array and I want to put all it contents back to the file (keeping line endings)...
Someone can tell me if there is a function that does the opposite of file()?
I want to bypass the annoying "array to string conversion" way...

Thanks in advance!

like image 247
Michele Avatar asked Oct 16 '25 17:10

Michele


1 Answers

Use file_put_contents() and implode():

file_put_contents('/your/file.php', implode(PHP_EOL, $fileArray));
like image 182
TiMESPLiNTER Avatar answered Oct 18 '25 05:10

TiMESPLiNTER



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!