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. 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]; } ?> 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 ! .. 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
Archived
This topic is now archived and is closed to further replies.