?
Solved

PHP Basename Question

Posted on 2012-09-16
5
Medium Priority
?
376 Views
Last Modified: 2012-09-17
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

0
Comment
Question by:laubacht
5 Comments
 
LVL 25

Expert Comment

by:lwadwell
ID: 38404341
try adding to the top of your script
    error_reporting(E_ALL);
and quotes around the script name.
0
 
LVL 6

Accepted Solution

by:
g3nu1n3 earned 900 total points
ID: 38404354
You need to put quotes in your comparison:

if ( $myURL == "codeTest.php" ) {

Open in new window

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 38404456
@g3nu1n3 is right.  Without the quotes, PHP looks for a constant by that name and of course it doesn't find it.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38404854
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
0
 
LVL 1

Author Comment

by:laubacht
ID: 38405931
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!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question