I have two files: one called AB.txt
, the other called A&B.txt
. For each, I run the following PHP code:
echo "[$arq]";
if (file_exists($arq)) {
echo '[found]';
} else {
echo '[none]';
}
The outputs are [AB.txt] [found]
and [A&B.txt] [none]
.
I tried replacing the &
with \&
inside file_exists()
, but it also doesn't work. And it doesn't seem to be a (lack of) UTF-8 problem.
Why is that? I'm on a Linux (Debian 11) machine, using PHP 7.4.
EDIT
var_dump(scandir('.'));
Returns hundreds of files (they're on a subdirectory, actually, but let's pretend they're not). I've removed all the other files from the list bellow.
array(352) { [302]=> string(7) "A&B.txt" [303]=> string(6) "AB.txt" }
EDIT 2
var_dump($f = "diffA&B.txt", file_exists($f), touch($f), file_exists($f));
string(11) "diffA&B.txt" bool(false) bool(true) bool(true)