What potential pitfalls should be considered when using PHP to manipulate text for file names?

One potential pitfall when using PHP to manipulate text for file names is the presence of special characters that are not allowed in file names, such as slashes, colons, and question marks. To avoid this issue, you can use the `preg_replace()` function to remove any unwanted characters from the input string before using it as a file name.

$input = "file/name:with?special*characters";
$cleaned_filename = preg_replace('/[^\p{L}\p{N}\s]/u', '', $input);
// $cleaned_filename now contains "filename with special characters"