PHP Basename Question

Posted on 2012-09-16
Last Modified: 2012-09-17
The code is pretty simple, but yet it still prints false... here is the live link..

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


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


Open in new window

Question by:laubacht
    LVL 25

    Expert Comment

    try adding to the top of your script
    and quotes around the script name.
    LVL 6

    Accepted Solution

    You need to put quotes in your comparison:

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

    Open in new window

    LVL 82

    Expert Comment

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

    Expert Comment

    by:Ray Paseur
    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.

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

    Second sidebar note: Learn about this function:

    Best of luck with your PHP adventures, ~Ray
    LVL 1

    Author Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
    In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
    In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now