ghostwalkz Posted February 17, 2009 Share Posted February 17, 2009 I have a string: $string = "somestuffthatchanges.somemorestuffthatchanges"; How can I strip everything before the first occurence of the period so it leaves me with just 'somemorestuffthatchanges'? Quote Link to comment https://forums.phpfreaks.com/topic/145495-string-question-help/ Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 explode $string = "somestuff.otherstuff"; list(, $string) = explode(".", $string); echo $string; Quote Link to comment https://forums.phpfreaks.com/topic/145495-string-question-help/#findComment-763854 Share on other sites More sharing options...
ghostwalkz Posted February 17, 2009 Author Share Posted February 17, 2009 That almost works, but.. if my string has 2 periods eg: $string = "somestuff.morestuff,finalstuff"; You solution only returns 'morestuff' whereas I need 'morestuff.finalstuff' If that makes any sense? Thanks for the help BTW! ;-) Quote Link to comment https://forums.phpfreaks.com/topic/145495-string-question-help/#findComment-763864 Share on other sites More sharing options...
premiso Posted February 17, 2009 Share Posted February 17, 2009 $string = "test.test.test.s"; $string = strstr($string, "."); echo $string; To remove the initial period you can make use of substr. Quote Link to comment https://forums.phpfreaks.com/topic/145495-string-question-help/#findComment-763869 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.