mcmuney Posted August 16, 2011 Share Posted August 16, 2011 Example: $filename = "image.jpg"; I'd like to display the $filename as "image" and ".jpg" separately. In other workds, show everything LEFT of the "." and everything RIGHT of the "." (including the dot) separately. What's the easiest method? Quote Link to comment https://forums.phpfreaks.com/topic/244898-parsing-data/ Share on other sites More sharing options...
harristweed Posted August 16, 2011 Share Posted August 16, 2011 <?php $filename = "image.jpg"; $dot=strpos($filename,"."); $first_part=substr($filename,0,$dot); $second_part=substr($filename,$dot); echo "first part =$first_part<br />\n"; echo "second part =$second_part"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244898-parsing-data/#findComment-1258021 Share on other sites More sharing options...
Nodral Posted August 16, 2011 Share Posted August 16, 2011 <?php $filename="image.jpg"; $split=explode(".",$filenames"); $name=$split[0]; $extension=$split[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244898-parsing-data/#findComment-1258024 Share on other sites More sharing options...
harristweed Posted August 16, 2011 Share Posted August 16, 2011 Yes but <?php $filename="image.jpg"; $split=explode(".",$filenames"); $name=$split[0]; $extension=$split[1]; ?> does not include the dot as request! <?php $filename="image.jpg"; $split=explode(".",$filename); $name=$split[0]; $extension=".".$split[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/244898-parsing-data/#findComment-1258027 Share on other sites More sharing options...
Nodral Posted August 16, 2011 Share Posted August 16, 2011 Sorry, missed that bit of the post. oops!!! Cheers for the correction. Quote Link to comment https://forums.phpfreaks.com/topic/244898-parsing-data/#findComment-1258028 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.