MDanz Posted June 8, 2010 Share Posted June 8, 2010 when i echo... how do i get the end of the string. i want to see if the end of the string is an image format. e.g. .jpeg, .gif, .bmp so if($variable ends with image format) {} else {} Quote Link to comment Share on other sites More sharing options...
Alex Posted June 8, 2010 Share Posted June 8, 2010 pathinfo $arr = array('jpg', 'bmp', 'gif', 'png' /* ... */); $info = pathinfo($variable, PATHINFO_EXTENSION); if(in_array($info['extension'], $arr)){ // ... } Quote Link to comment Share on other sites More sharing options...
MDanz Posted June 8, 2010 Author Share Posted June 8, 2010 can't seem to get this working. I put the variable $info as test.jpg $arr = array('jpg', 'bmp', 'gif', 'png' /* ... */); $check = pathinfo($info, PATHINFO_EXTENSION); if(in_array($check['extension'], $arr)){ $query = "INSERT INTO Stacks"; $query .= "(`username`,`image`,`reply`,`number`,`ip`,`origin`,`keywords`,`avatar`,`Positive`,`Negative`) VALUES ('$usernames','$reply','$reply $info','$id','$ip',$org+1,'$keywords','$avatarreply','$pos1','$neg1')"; $results = mysql_query($query, $dlink); echo "worked"; } else { $query = "INSERT INTO Stacks"; $query .= "(`username`,`reply`,`number`,`ip`,`origin`,`keywords`,`avatar`,`Positive`,`Negative`) VALUES ('$usernames','$reply $info','$id','$ip',$org+1,'$keywords','$avatarreply','$pos1','$neg1')"; $results = mysql_query($query, $dlink); echo "didn't work"; } it should echo didn't work.. Quote Link to comment Share on other sites More sharing options...
Alex Posted June 8, 2010 Share Posted June 8, 2010 My mistake, I forgot that pathinfo doesn't return an array when you specify a specific option to return. $arr = array('jpg', 'bmp', 'gif', 'png' /* ... */); if(in_array(pathinfo($variable, PATHINFO_EXTENSION), $arr)){ // ... } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.