-3

I am trying to check if a current path is being used, for example:

www.mydomain.com/abc/123/content

How do I go about checking whether the current path is abc i.e. the check should succeed for all abc e.g. abc/123/content as well as abc/456/content but fail otherwise e.g. for bcd/123/content

thanks

badcoder
  • 3,624
  • 5
  • 32
  • 33
  • "Is being used", do you mean exists? – craig1231 Dec 05 '11 at 13:22
  • possible duplicate of [how do i parse url php](http://stackoverflow.com/questions/5624370/how-do-i-parse-url-php) – Polynomial Dec 05 '11 at 13:23
  • Duplicate of http://stackoverflow.com/questions/5598480/php-parse-current-url http://stackoverflow.com/questions/5624370/how-do-i-parse-url-php and probably fifty other duplicates. – Polynomial Dec 05 '11 at 13:23

1 Answers1

1

Get the current url with $_SERVER['PHP_SELF'] and than look if the string contains 'abs' with the strpos function. Like:

<?php
    if (strpos($_SERVER['PHP_SELF'], 'abc') !== false)
        //found
?>
Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
  • 2
    actually, strpos( 'abc/foo', 'abc' ) would return 0 (as the substring starts at position 0. Append a !== false, and you're right ;) – Berry Langerak Dec 05 '11 at 13:28
  • I would also use stripos() instead of strpos() because it's case-insensitive so 'ABC/FOO' will still work. – NexusRex Jan 24 '12 at 08:32