lxndr Posted March 12, 2007 Share Posted March 12, 2007 I know this should be easy but I just can't get it to work. What I want to do is process a string and extract just those characters between a pair of double quotes: i.e. input string: 'blah blah', "text" output string: text input string: 'some characters', "more text" output string: text The input strings are read in from a text file. Thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/42402-solved-extracting-the-text-between-quotation-marks/ Share on other sites More sharing options...
obsidian Posted March 12, 2007 Share Posted March 12, 2007 Try this regexp: <?php $string = "'some text' \"more text\""; if (preg_match('|(")([^"]+)\\1|', $string, $match)) { // Found a match: echo $match[2]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/42402-solved-extracting-the-text-between-quotation-marks/#findComment-205684 Share on other sites More sharing options...
lxndr Posted March 12, 2007 Author Share Posted March 12, 2007 Try this regexp: <?php $string = "'some text' \"more text\""; if (preg_match('|(")([^"]+)\\1|', $string, $match)) { // Found a match: echo $match[2]; } ?> Thanks very much, that's working nicely ! .. Quote Link to comment https://forums.phpfreaks.com/topic/42402-solved-extracting-the-text-between-quotation-marks/#findComment-205693 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.