How to read the contents of a file into a string in PHP

file_get_contents() can help us here. It reads a file and stores it in a string. Can be used with local files, as well as online content:

This is different from the file() function which reads the contents of a file into an array.

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!