sungpeng Posted July 1, 2009 Share Posted July 1, 2009 $variable="bedroom.jpg"; Can check with all of you how to ignore the ".jpg" and get the character "bedroom" only? Link to comment https://forums.phpfreaks.com/topic/164341-ignore-last-4-characters/ Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 $variable="bedroom.jpg"; $vararr=explode(".",$variable); $variable=$vararr[0]; Link to comment https://forums.phpfreaks.com/topic/164341-ignore-last-4-characters/#findComment-866882 Share on other sites More sharing options...
sungpeng Posted July 1, 2009 Author Share Posted July 1, 2009 Thank abdbuet Link to comment https://forums.phpfreaks.com/topic/164341-ignore-last-4-characters/#findComment-866885 Share on other sites More sharing options...
joel24 Posted July 1, 2009 Share Posted July 1, 2009 but if it were a file like 'bedroom.old.jpg', explode wouldn't work? well it would, but you'd only get 'bedroom' and not 'bedroom.old' you can use the pathinfo() function http://us3.php.net/manual/en/function.pathinfo.php $file = 'bedroom.jpg'; $filename = pathinfo($bedroom, PATHINFO_FILENAME); Link to comment https://forums.phpfreaks.com/topic/164341-ignore-last-4-characters/#findComment-866888 Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 yup .. ryt .. or may be $variable = substr($variable, 0, -4); there are lots of alternate way as well Link to comment https://forums.phpfreaks.com/topic/164341-ignore-last-4-characters/#findComment-866892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.