如何使用PHP只返回我的文件名的第一部分,而不是扩展名“.php”

I am trying to set the ID of the <body> tag to be the name of the current page...

<body id="<?= basename($_SERVER['PHP_SELF'])?>">

Why is this returning:

<body id="wildlife.php">

?

I want just the word "wildlife."

I think you need to add the extension suffix to strip off, Try this

<body id="<?= basename($_SERVER['PHP_SELF'],'.php')?>">

http://php.net/manual/en/function.basename.php

You can do that:

if (preg_match('#([^/]+)\.\w+$#', 'http://www.mysite.com/home.php', $matches))
    $basename = $matches[1];

Try it this way :

basename($PHP_SELF,".php");