SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot amit290's Avatar
    Join Date
    Oct 2001
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use a wildcard in PHP

    What is a wildcard in PHP?

    I need to set a variable if the URL has "/thisfolder/" in the address.

    I thought of something like this....

    PHP Code:
    if($PHP_SELF == "%foldername%") {
        
    $setvariable "tosomething";
    } else {
        
    //do nothing

    But it doesnt work

    Any ideas?

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    strstr, preg_match, etc. Just look up the the string functions in the manual.

  3. #3
    SitePoint Member
    Join Date
    Sep 2003
    Location
    London
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no wildcard as such like in SQL or shell scripting. You need to use one of PHPs string handling functions to massage the strings:

    PHP Code:
    if(strpos($PHP_SELF'foldername') !== FALSE) {
        
    $setvariable "tosomething";

    The strpos() function manual entry is at http://uk.php.net/strpos

  4. #4
    SitePoint Zealot amit290's Avatar
    Join Date
    Oct 2001
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Peejeh, exactly what I was looking for. Did the job.

    strstr, preg_match, etc. Just look up the the string functions in the manual
    Will take a look at these when I get some free time

  5. #5
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a reminder, $PHP_SELF only works with register_globals = on which isn't in newer PHP versions, you should use $_SERVER['PHP_SELF'] if you have PHP >= 4.2.0


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •