eddie_ Posted December 13, 2014 Share Posted December 13, 2014 First time post, be easy on me... I'm using preg_match_all to return an array with all the matches. I know I'm missing something fundamental, but I either keep looking past it or am more screwy than I know. Sample String CC-BY-ND-NC I'm using the following code preg_match_all("/cc|creative commons|copyright|by|sa|nc|nd/i",$exifmeta['copyright'],$cmeta) I would expect to see Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC ) ) What I get is Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC [4] => sa ) ) Link to comment https://forums.phpfreaks.com/topic/293079-preg_match_all-returns-matches-that-doesnt-exist/ Share on other sites More sharing options...
Ch0cu3r Posted December 13, 2014 Share Posted December 13, 2014 Are you sure that is the exact string stored in $exifmeta['copyright'] What does var_dump($exifmeta['copyright']) show? Link to comment https://forums.phpfreaks.com/topic/293079-preg_match_all-returns-matches-that-doesnt-exist/#findComment-1499514 Share on other sites More sharing options...
eddie_ Posted December 13, 2014 Author Share Posted December 13, 2014 Well, I feel a little sheepish It appears that I have a url in the string that just happens to have "SA" in it. string(30) "CC-BY-NC-ND https://urlwithSAinit.com" How can I better wright the regex to take that into consideration? Link to comment https://forums.phpfreaks.com/topic/293079-preg_match_all-returns-matches-that-doesnt-exist/#findComment-1499528 Share on other sites More sharing options...
Ch0cu3r Posted December 14, 2014 Share Posted December 14, 2014 Maybe use a word boundary? /\b(cc|creative commons|copyright|by|sa|nc|nd)\b/i Link to comment https://forums.phpfreaks.com/topic/293079-preg_match_all-returns-matches-that-doesnt-exist/#findComment-1499557 Share on other sites More sharing options...
Regexer Posted December 21, 2014 Share Posted December 21, 2014 use \s instead of pure space symbol Link to comment https://forums.phpfreaks.com/topic/293079-preg_match_all-returns-matches-that-doesnt-exist/#findComment-1500230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.