Skip to content
PHP Logo

What is the significance of using "|" at the end of the text when writing to a file in PHP?

When writing to a file in PHP, using "|" at the end of the text signifies the end of the file. This is important because it ensures that the file pointer is placed at the end of the file before writing additional content. This prevents overwriting existing content in the file and allows for appending new data to the end of the file.

php
$file = fopen("example.txt", "a"); // "a" mode opens the file for writing only; places the file pointer at the end of the file
fwrite($file, "New content to add to the file|"); // using "|" at the end ensures that new content is appended to the end of the file
fclose($file);