Can someone give me an snipet of a code to show me how the this line of code works?

strpos($_SERVER['PHP_SELF'], $url)

I read the php manual and I found out that

strpos : gives me the the position of a needle in a heystack if it exist or returns a boolean false if it does not.

PHP_SLFE: gives the filename of the currently executing script, relative to the document root.

thank you

    All it does is find a string within another string.

    Let's take an example:

    Assume you have a website named http://www.MyWebSite.com

    And a script named TestIt.php as shown below:

    <?php

    echo $SERVER['PHP_SELF'] . "<br />";
    $url = "TestIt.php";
    $retVal = strpos($
    SERVER['PHP_SELF'], $url);
    if ($retVal == FALSE)
    echo $url . " not found in " . $_SERVER['PHP_SELF'] . "<br />";
    else
    echo $url . " found in position " . $retVal . "<br />";

    ?>

    So if you ran the code above, you would get the following output:

    /MyWebSite.com/TestIt.php
    TestIt.php found in position 15

    Now if you changed $url to "MyWebSite.com", strpos would return 1

    Make sense?

      Kerry,

      It sure does. Thank you so much for the wonderful example. I get it much more clearly now.

        Your welcome Masood... hope the weather is nice up there in SF. It's been terrific down here in SJ. 😃

          Write a Reply...