first off, basename might not be working the way you want it to--this is no fault of your own.
basename(dir/whatever.ext) will return the filename, with extension, as expected; but to return a filename
without extension using the suffix parameter, as you have with basename($full_path,".php") your server needs to be running php version 4.1.0. my server is running 4.0.6 and this wouldn't work for me either. so you need to strip off the extension in some other manner.
try this:
PHP:
$filename = current(explode('.', basename($SCRIPT_NAME)));
here's what happens, from the inside out:
does what it looks like, taking the basename (with extension, remember) from whatever page the command is on.
next, we use the
explode command to break that result into an array, using the '.' as our break point.
finally, we use the
current command to retrieve the current element of this array. since we haven't done anything to this array yet, the pointer is still on the first element -- just what we want, the first bit of that filename.
so: you've arrived at a good basename. now you need to append the correct .inc suffix. your command,
won't work because of that period. in php, the period acts as a concatenator; meaning that it appends one string to another.
prints: "hello world".
likewise, if your basename is "thisfile,"
asks the php engine to include "thisfileinc" because it just runs the two together. and without quotes, that
inc isn't going to do any good, either, because php won't know it's a string. instead, use the concatenator like this:
this will result in an include of filename.inc. see the difference?
so your complete code looks like this:
PHP:
<?php
$filename = current(explode('.', basename($SCRIPT_NAME)));
include($filename.'.inc');
?>
placing this in anyfile.php will result in an include of anyfile.inc
hope this helps!!