What are the potential pitfalls of using the 'r+' mode in fopen when working with files in PHP?

Using the 'r+' mode in fopen when working with files in PHP can lead to potential pitfalls such as accidentally truncating the file or overwriting its contents. To avoid these issues, it is recommended to use the 'r+b' mode instead, which allows for reading and writing without truncating the file.

$file = fopen("example.txt", "r+b");
if ($file) {
    // Perform read and write operations here
    fclose($file);
} else {
    echo "Error opening file.";
}