What potential issue can arise when using fopen with the r+ mode in PHP?

When using fopen with the r+ mode in PHP, a potential issue that can arise is that the file pointer is positioned at the beginning of the file, which may overwrite existing content when writing to the file. To solve this issue, you can use fseek to move the file pointer to the end of the file before writing.

$file = fopen("example.txt", "r+");
fseek($file, 0, SEEK_END); // move file pointer to the end of the file
fwrite($file, "New content to append\n");
fclose($file);