I want to remove \".php\" from the end of a string if it exists. Consider this:
$filename = \'index\';
rtrim($filename,\".php\");//returns \"index\"
$filena
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$/", "$1", $filename); instead, or basename($filename, '.php') if you have the file on the server, not just in a string.