What are the potential pitfalls of using ".include()." in PHP for including text?

One potential pitfall of using ".include()." in PHP for including text is that it can expose sensitive data if the file path is not properly sanitized. To solve this issue, always validate and sanitize user input before using it in the include statement to prevent directory traversal attacks.

// Validate and sanitize user input before using it in include statement
$file = filter_var($_GET['file'], FILTER_SANITIZE_STRING);
include('path/to/directory/' . $file);