rtrim accepts a list of characters as the second argument, so in this case, it will trim not just the .php extension, but any ., p, or h characters found in the rest of the string.
Try using preg_replace("/(.+)\.php instead, or 1", $filename);
basename($filename, '.php') if you have the file on the server, not just in a string.
What does PHP rtrim() do and how does it work?
How can I remove trailing slashes or dots in PHP?
$url = "example.com///";
echo rtrim($url, "/"); // "example.com"
This removes all slashes from the end of the string. You can also remove dots by passing "." or any combination like ".-/".rtrim accepts a list of characters as the second argument, so in this case, it will trim not just the .php extension, but any ., p, or h characters found in the rest of the string.
Try using preg_replace("/(.+)\.php instead, or 1", $filename);
basename($filename, '.php') if you have the file on the server, not just in a string.
The second argument to rtrim is a string with a list of characters. In this case, it will strip off any P, H, and . in your string, so returning searc.