newcoder21 Posted October 9, 2009 Share Posted October 9, 2009 Hi I new to php and this forum , I need some help getting rid of some extra stuff in a string the string will contain info like "i my name is joe (dfdsfds jdsjkfjdsk)" I want to cut out any thing in "(dfdsfds jdsjkfjdsk)" so the string would look like "i my name is joe" so any thing between this "(random info)" is they any way I can just cut off the end of the string starting with this"(" ? thank you for any help Quote Link to comment https://forums.phpfreaks.com/topic/177031-solved-need-help-rid-of-stuff-in-a-string/ Share on other sites More sharing options...
mikesta707 Posted October 9, 2009 Share Posted October 9, 2009 you can use regex, or a combination of str_replace, strstr() and strrstr(). try reading the manual on regex, or those functions Quote Link to comment https://forums.phpfreaks.com/topic/177031-solved-need-help-rid-of-stuff-in-a-string/#findComment-933418 Share on other sites More sharing options...
newcoder21 Posted October 9, 2009 Author Share Posted October 9, 2009 I tried those before the problem I have is the stuff I have in string changes so I was trying to find a way to chop the string off when it finds the first "(" you can use regex, or a combination of str_replace, strstr() and strrstr(). try reading the manual on regex, or those functions Quote Link to comment https://forums.phpfreaks.com/topic/177031-solved-need-help-rid-of-stuff-in-a-string/#findComment-933422 Share on other sites More sharing options...
.josh Posted October 9, 2009 Share Posted October 9, 2009 you can use strpos to find the first occurance of "(" it will return the character position in the string. You can then use substr to extract the part you want, starting at 0, and using the # returned from strpos for the length. Quote Link to comment https://forums.phpfreaks.com/topic/177031-solved-need-help-rid-of-stuff-in-a-string/#findComment-933429 Share on other sites More sharing options...
newcoder21 Posted October 9, 2009 Author Share Posted October 9, 2009 thank you that worked great!!! you can use strpos to find the first occurance of "(" it will return the character position in the string. You can then use substr to extract the part you want, starting at 0, and using the # returned from strpos for the length. Quote Link to comment https://forums.phpfreaks.com/topic/177031-solved-need-help-rid-of-stuff-in-a-string/#findComment-933447 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.