kodie Posted September 20, 2010 Share Posted September 20, 2010 Hey guys, I've got a little problem that I can't seem to find the answer to... I have a string like this: $oldstring = "<test1>here is some text</test1>"; and what I want to do is get "test1" and "here is some text" into 2 separate strings kind of like this: $newstring[0] = "test1"; $newstring[1] = "here is some text"; I figured I'd use preg_replace to do this but no luck. I know the answer has to be something simple but I just can't figure it out. Thanks for any help you can give! Quote Link to comment Share on other sites More sharing options...
schilly Posted September 20, 2010 Share Posted September 20, 2010 preg_match('/<([a-z,\d]*)>([a-z,\s,\d]*)</[a-z,\d]*>/i',$string,$matches); try that. Quote Link to comment Share on other sites More sharing options...
kodie Posted September 20, 2010 Author Share Posted September 20, 2010 preg_match('/<([a-z,\d]*)>([a-z,\s,\d]*)</[a-z,\d]*>/i',$string,$matches); try that. Thanks for the reply, That doesn't return anything, even tried print_r($matches); and it's empty. Quote Link to comment Share on other sites More sharing options...
schilly Posted September 20, 2010 Share Posted September 20, 2010 preg_match('/<([a-z,\d]*)>([a-z,\s,\d]*)<\/[a-z,\d]*>/i',$string,$matches); ooops. needed to escape backslash. try that. i just tested it and it works. Quote Link to comment Share on other sites More sharing options...
kodie Posted September 20, 2010 Author Share Posted September 20, 2010 preg_match('/<([a-z,\d]*)>([a-z,\s,\d]*)<\/[a-z,\d]*>/i',$string,$matches); ooops. needed to escape backslash. try that. i just tested it and it works. Works perfect! Thanks a bunch! Quote Link to comment 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.