exploding a file name to separate the name and extension won't work in PHP?
I'm building a class that returns an string that will include files in a folder automatically, kinda like a loader for an HTML file.
Here's the method that will be called:
So, this runs without any errors. But, it doesn't do what it's supposed to do... or at least what I intend it to do. Technically speaking here,
$fileName should be the extension js
$fileName should be name of the file main
$fileName is main.js.
does explode not recognize .?
Thank you in advance.
You're forcing your resulting array to have 1 element, which causes it to have the entire filename.
explode( '.', $ext, 1 )
should instead be
explode( '.', $ext );
You've limited the explode to producing 1 array entry, so it can never do anything:
print_r(explode('.', 'a.b', 1)); Array (  => a.b )
The limit should be at least 2. or, better yet, you should be using the pathinfo() function, which properly handles filename components for you.