ghostwalkz Posted January 20, 2009 Share Posted January 20, 2009 Hi all, I have a string: $foo = "blahblahblahrandomstuff {youtube}imdKQ3NNnoM{/youtube} moreblahblahblahrandomstuff"; I need to extract the 'imdKQ3NNnoM' from inside the {youtube} tags. Any ideas - a code example would be muchly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/141653-extracting-a-string-from-a-string-stuck/ Share on other sites More sharing options...
premiso Posted January 20, 2009 Share Posted January 20, 2009 Is that how the string is actually formatted? If not then post the actual string you want to parse, without that we are shooting blanks. Quote Link to comment https://forums.phpfreaks.com/topic/141653-extracting-a-string-from-a-string-stuck/#findComment-741513 Share on other sites More sharing options...
ghostwalkz Posted January 20, 2009 Author Share Posted January 20, 2009 thats it, anything outside the youtube tag is random and can change. The constant is the tag. I need to extract whats in that tag. Thanks in advance. :-) Quote Link to comment https://forums.phpfreaks.com/topic/141653-extracting-a-string-from-a-string-stuck/#findComment-741518 Share on other sites More sharing options...
premiso Posted January 20, 2009 Share Posted January 20, 2009 REGEX might be better but this will also work. <?php $foo = "blahblahblahrandomstuff {youtube}imdKQ3NNnoM{/youtube} moreblahblahblahrandomstuff"; list($before) = explode("{/youtube}", $foo); list(,$before) = explode("{youtube}", $before); echo $before; ?> Now you may have to escape the { and } if it gives you an error to be \{youtube\} but give that a try and see. Quote Link to comment https://forums.phpfreaks.com/topic/141653-extracting-a-string-from-a-string-stuck/#findComment-741524 Share on other sites More sharing options...
ghostwalkz Posted January 20, 2009 Author Share Posted January 20, 2009 Perfect, works great (no escape ness), thankyou, thanks, gracias, muchos gracias, etc etc. Quote Link to comment https://forums.phpfreaks.com/topic/141653-extracting-a-string-from-a-string-stuck/#findComment-741528 Share on other sites More sharing options...
premiso Posted January 20, 2009 Share Posted January 20, 2009 Glad to hear. Remember to mark this as solved (bottom left hand corner). Quote Link to comment https://forums.phpfreaks.com/topic/141653-extracting-a-string-from-a-string-stuck/#findComment-741539 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.