PHP display if...

Discussion in 'PHP' started by cavendano, Mar 3, 2008.

  1. #1
    I have a script that lists directories..now I needed for the script to link to another page when a certain type of file has an extension that is listed.
    Right now its echoing the argument whether or not the file with the extension is there...
    can someone look at this and see the mistake?
    $ext = array_pop(explode(".", $file)); 
    
    if (strpos("|m4a|mp3|jpg|jpeg|wav|jar|jad|qcp", $ext))
    $filezz = $ext;
    echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"text-transform: uppercase\"><a href=\"?page=filter&location=$starto&section=$startp\">Click Here To Proceed</font></a>&nbsp;&nbsp;&nbsp;</td>\n";
    die;
    PHP:
    Thanks for the help!
     
    cavendano, Mar 3, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    strpos() doesn't take patterns like that. Use preg_match() instead:
    
    if (preg_match("~m4a|mp3|jpg|jpeg|wav|jar|jad|qcp~i", $ext))
    
    PHP:
     
    nico_swd, Mar 3, 2008 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    You could also put all of those extensions in an array, and use in_array(). A little lighter than preg_match, but not a huge difference.

    
    $valid = array('m4a','mp3','jpg','jpeg','wav','jar','jad','qcp');
    
    if(in_array($ext,$valid))
    {
    
    //everythigs OK
    
    }
    
    
    PHP:
     
    jestep, Mar 3, 2008 IP
  4. quicksolutions

    quicksolutions Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this one!!!!!

    echo "<td>&nbsp;&nbsp;&nbsp;&nbsp;<span style='text-transform: uppercase'><a href='?page=filter&location=$starto&section=$startp'>Click Here To Proceed</font></a>&nbsp;&nbsp;&nbsp;</td>\n";
     
    quicksolutions, Mar 4, 2008 IP