What are the advantages and disadvantages of using text files instead of a database for storing website data in PHP?

Using text files for storing website data in PHP can be advantageous because they are simple to implement, do not require a database management system, and are easily portable. However, text files may not be as efficient for handling large amounts of data, may not support complex queries, and may be less secure compared to using a database.

// Example of storing data in a text file
$data = "John,Doe,30\nJane,Smith,25\n";
file_put_contents('data.txt', $data);

// Example of reading data from a text file
$file = file_get_contents('data.txt');
$lines = explode("\n", $file);
foreach ($lines as $line) {
    $fields = explode(",", $line);
    echo "Name: $fields[0] $fields[1], Age: $fields[2]\n";
}