SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: ereg for jpg???

  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy ereg for jpg???

    Hello, I am trying to get ereg to return true if it finds any combination for jpg in a file type (jpeg, pjpeg, jpg, etc) how do I do this???

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is this what you're looking for?

    PHP Code:
    if(ereg('(jpe?g|pjpeg)'$filetype)) 
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tired that but it doesnt work...

    image/jpeg

    --> I want it to detect if its a jpeg file by using any combination of jp?g but I dont know how to do that jejeej

  4. #4
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function is_jpeg($filename)
    {
            
    $extension strtolower(substr(strrchr($filename'.'), 1));
            
    in_array($extension, array('jpg''jpeg''pjpeg')) ? true false;

    Just a quick something I rustled up

  5. #5
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Try the following:

    PHP Code:
    $filetype 'image/jpeg';

    if( 
    preg_match('/^image\/(pjpeg|jpe?g)$/i'$filetype) )
    {
      echo 
    'Yes, it was fine...';

    ERIK RIKLUND :: Yes, I've been gone quite a while.

  6. #6
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dean C
    PHP Code:
      function is_jpeg($filename)
      {
              
    $extension strtolower(substr(strrchr($filename'.'), 1));
              
    in_array($extension, array('jpg''jpeg''pjpeg')) ? true false;
      } 
    Just a quick something I rustled up
    A bit too quick perhaps

    function is_jpeg($filename)
    {
    $extension = strtolower(end(explode('.', $filename)));
    return in_array($extension, array('jpg', 'jpeg', 'pjpeg')) ? true : false;
    }

    Would probably work a bit better.

    Acutally, yours would work, except the return is missing.


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
  •