0

Can someone please help me with these 4 lines of code. I been trying to read how to fix this error but I'm not very familiar with php that much yet.

$currentFile = $_SERVER["SCRIPT_NAME"];
$img = array_pop(explode("/", $currentFile));
$fileName = basename($img, ".php").PHP_EOL;
echo $fileName;

This script finds the current $.php name and spits it out. It also cuts the location of the file and the extension as well... leaving just the fileName.

How would I write these 4 lines of code to not throw that Strict Standard error

user1707535
  • 169
  • 1
  • 9

1 Answers1

2

Just add a varible.

$currentFile = $_SERVER["SCRIPT_NAME"];
$ret = explode("/", $currentFile);
$img = array_pop($ret);
$fileName = basename($img, ".php").PHP_EOL;
echo $fileName;

But you could just use basename only, the below code will give you same result:

$fileName = basename($_SERVER["SCRIPT_NAME"], ".php").PHP_EOL;
xdazz
  • 158,678
  • 38
  • 247
  • 274