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! Link to comment https://forums.phpfreaks.com/topic/213931-preg_replace-html-formatting/ 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. Link to comment https://forums.phpfreaks.com/topic/213931-preg_replace-html-formatting/#findComment-1113420 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. Link to comment https://forums.phpfreaks.com/topic/213931-preg_replace-html-formatting/#findComment-1113423 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. Link to comment https://forums.phpfreaks.com/topic/213931-preg_replace-html-formatting/#findComment-1113430 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! Link to comment https://forums.phpfreaks.com/topic/213931-preg_replace-html-formatting/#findComment-1113442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.