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 {} Link to comment https://forums.phpfreaks.com/topic/204144-end-of-string-help/ 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)){ // ... } Link to comment https://forums.phpfreaks.com/topic/204144-end-of-string-help/#findComment-1069225 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.. Link to comment https://forums.phpfreaks.com/topic/204144-end-of-string-help/#findComment-1069233 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)){ // ... } Link to comment https://forums.phpfreaks.com/topic/204144-end-of-string-help/#findComment-1069234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.