What alternatives can be used in PHP to separate data in a text file without using the newline character?

When separating data in a text file without using the newline character, one alternative is to use a different delimiter such as a comma, tab, or pipe symbol. This allows for the data to be easily parsed and extracted without relying on the presence of newline characters. By using a unique delimiter, you can ensure that the data remains organized and structured within the text file.

<?php
// Data to be written to the text file
$data = "John,Doe,30|Jane,Smith,25|Alex,Johnson,35";

// Write data to the text file using a pipe symbol as the delimiter
$file = fopen("data.txt", "w");
fwrite($file, $data);
fclose($file);

// Read data from the text file using the pipe symbol as the delimiter
$file = fopen("data.txt", "r");
$data = fread($file, filesize("data.txt"));
$records = explode("|", $data);

foreach($records as $record) {
    $fields = explode(",", $record);
    echo "First Name: $fields[0], Last Name: $fields[1], Age: $fields[2]" . PHP_EOL;
}

fclose($file);
?>