Link to home
Start Free TrialLog in
Avatar of laubacht
laubacht

asked on

PHP Basename Question

The code is pretty simple, but yet it still prints false... here is the live link..

http://www.tornadoeskick.com/tonylaubach/codeTest.php

Obviously the filename is codeTest.php, but it won't display true for some reason?  Any suggestions?

<?php
$myURL=basename(basename($_SERVER['REQUEST_URI']));

echo "$myURL";
?>
<br><br>
<?php
if ( $myURL == codeTest.php ) {
	echo "The if statement evaluated to true";
} else {
	echo "The if statement evaluated to false";
}

?>

Open in new window

Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

try adding to the top of your script
    error_reporting(E_ALL);
and quotes around the script name.
ASKER CERTIFIED SOLUTION
Avatar of g3nu1n3
g3nu1n3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@g3nu1n3 is right.  Without the quotes, PHP looks for a constant by that name and of course it doesn't find it.
Grab a copy of this book.  It will not make you a pro, but it will give you enough of a foundation in the basics of PHP to avoid simple syntax errors like this one.
http://www.sitepoint.com/books/phpmysql5/

Sidebar note: You only need to call the basename() function once.

Second sidebar note: Learn about this function:
http://us2.php.net/manual/en/function.var-dump.php

Best of luck with your PHP adventures, ~Ray
Avatar of laubacht
laubacht

ASKER

The quotes did it... I appreciate the fast help on that!  Working a website without using Wordpress or something along those lines, so doing a lot of this from scratch!  Thanks guys!