dmccabe Posted July 6, 2011 Share Posted July 6, 2011 Ok I have this text: User Name (Real Name) I want to grab the text "User Name" and "Real Name" separately? How can I split them, I know it has something to do with Strpos and Substr, but I just cant get it right or anywhere close, this is where I get before getting all kinds of confused: $pos = strpos($author, "("); $name= substr($author, $pos, -1); Quote Link to comment https://forums.phpfreaks.com/topic/241268-grabbing-all-the-text-in-a-text-to-the-left-of-a-token/ Share on other sites More sharing options...
Zane Posted July 6, 2011 Share Posted July 6, 2011 $text = "User Name (Real Name)"; $regex = preg_match("/^(.*)\s\((.*)\)$/", $text, $matches); $username = $matches[1]; $realname = $matches[2]; Quote Link to comment https://forums.phpfreaks.com/topic/241268-grabbing-all-the-text-in-a-text-to-the-left-of-a-token/#findComment-1239339 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.