chrisran Posted August 4, 2009 Share Posted August 4, 2009 Hi, I'm again trying to match against html, but it works only partly. $string = "<option title='(71) (1)'>Phase71 Cluster1</option><option title='(49) (1)'>Phase49 Cluster1</option><option title='(36) (1)'>Phase36 Cluster1</option>"; What I've tried: $getteklistexp = "/title='\(.*?\)[^>]*\(.*?\)'>.*?<\/option><option/"; I cant use "<option title" because sometimes I have a id=xyz in between, therefore I try to grep on title=' and then I'd like to have an array like this: [0] = 71 [1] = 1 [2] = Phase71 Cluster1 [3] = 49 [4] = 1 [5] = Phase49 Cluster1 ... My result is: [0] => title='(71) (1)'>Phase1 Cluster1 What am I missing this time ? Thanks Link to comment https://forums.phpfreaks.com/topic/168826-solved-matching-123-51-parentheses-and-a-bit-html/ Share on other sites More sharing options...
thebadbad Posted August 4, 2009 Share Posted August 4, 2009 <?php $string = "<option title='(71) (1)'>Phase71 Cluster1</option><option title='(49) (1)'>Phase49 Cluster1</option><option title='(36) (1)'>Phase36 Cluster1</option>"; preg_match_all("~title='\(([0-9]+)\) \(([0-9]+)\)'>([^<]+)<~i", $string, $matches, PREG_SET_ORDER); //put all captured matches in a single-dimension array $singledim = array(); foreach ($matches as $arr) { array_shift($arr); $singledim = array_merge($singledim, $arr); } echo '<pre>' . print_r($singledim, true) . '</pre>'; ?> Output: Array ( [0] => 71 [1] => 1 [2] => Phase71 Cluster1 [3] => 49 [4] => 1 [5] => Phase49 Cluster1 [6] => 36 [7] => 1 [8] => Phase36 Cluster1 ) Link to comment https://forums.phpfreaks.com/topic/168826-solved-matching-123-51-parentheses-and-a-bit-html/#findComment-890752 Share on other sites More sharing options...
chrisran Posted August 4, 2009 Author Share Posted August 4, 2009 Thanks so much for the quick answer, it works like a charm. Finally :-) Link to comment https://forums.phpfreaks.com/topic/168826-solved-matching-123-51-parentheses-and-a-bit-html/#findComment-890761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.