hatrickpatrick Posted November 17, 2007 Share Posted November 17, 2007 Supposing I have a string, $string="hello.world.today"; Is there any function I can use to isolate everything after the last ., so it would output "today" on its own? I'm trying to isolate the file extension of a URL (for example, www.whatever.com/index.php -> isolate 'php', or www.google.ie/index.html -> isolate 'html'). Is this possible? Any help would be much appreciated... Quote Link to comment https://forums.phpfreaks.com/topic/77681-isolate-different-parts-of-a-string-aka-everything-after-the-last/ Share on other sites More sharing options...
teng84 Posted November 17, 2007 Share Posted November 17, 2007 $path = "/home/httpd/html/index.php"; echo basename($path).'<br />'; echo basename($path, ".php"); try .... Quote Link to comment https://forums.phpfreaks.com/topic/77681-isolate-different-parts-of-a-string-aka-everything-after-the-last/#findComment-393246 Share on other sites More sharing options...
kenrbnsn Posted November 17, 2007 Share Posted November 17, 2007 Look at the functions parse_url() and pathinfo(). You should be able to do what you want to do using a combination of these functions. Ken Quote Link to comment https://forums.phpfreaks.com/topic/77681-isolate-different-parts-of-a-string-aka-everything-after-the-last/#findComment-393247 Share on other sites More sharing options...
wsantos Posted November 17, 2007 Share Posted November 17, 2007 substr(string,strrpos(string,".")) Quote Link to comment https://forums.phpfreaks.com/topic/77681-isolate-different-parts-of-a-string-aka-everything-after-the-last/#findComment-393248 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.