title: php check if a image file name end is not .jpg, .jpeg, .png or .gif.
body: <p>I tried to save web image to local, I use code here to make a judge, if image file name end is not .jpg, .jpeg, .png or .gif, add them. I use <code>stripos</code>, but I meet some trouble when an image url like this. So how to solve? Thanks. </p>
  
  <pre><code>$webimage = 'http://pcdn.500px.net/5953805/d0dd841969187f47e8ad9157713949b4b95b3bda/4.jpg?1333782904356';
  $pieces = explode("/", $webimage); 
  $pathend = end($pieces);
  $imageinfo = @getimagesize($webimage);
  $imagetype= $imageinfo['mime'];
  if($imagetype=='image/jpeg'){
      if(stripos($pathend,'.jpg')==0){
          $newpathend = $pathend.'.jpg'; // if image end is't '.jpg', add '.jpg'
      }else if(stripos($pathend,'.jpeg')==0){
          $newpathend = $pathend.'.jpeg'; // if image end is't '.jpg', add '.jpeg'
      }else{
          $newpathend = $pathend;// if image end is '.jpg' or '.jpeg', do not change
      }
  }
  if($imagetype=='image/png'){
      if(stripos($pathend,'.png')==0){
          $newpathend = $pathend.'.png'; // if image end is't '.png', add '.png'
      }else{
          $newpathend = $pathend;// if image end is '.png', do not change
      }
  }
  if($imagetype=='image/gif'){
      if(stripos($pathend,'.gif')==0){
          $newpathend = $pathend.'.gif'; // if image end is't '.gif', add '.gif'
      }else{
          $newpathend = $pathend;// if image end is '.gif', do not change
      }
  }
  </code></pre>