dtdetu Posted November 16, 2008 Share Posted November 16, 2008 hello i want to get the 29.31 from this code , the 51 and 29.31 is variable but Industries is stable, can someone show me the pattern pls. <td>Industries</td> <td>51</td> <td>29.31%</td> i am using this code but doesnt work preg_match("~<td>Industries</td><td>[^*]</td><td>(.*?)</td>~i", $string, $result) ; $result = $result{1]; echo $result; Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/ Share on other sites More sharing options...
JasonLewis Posted November 16, 2008 Share Posted November 16, 2008 Try this pattern: preg_match("#([\d\.]+)%#i", $str, $matches); echo $matches[1]; Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691272 Share on other sites More sharing options...
dtdetu Posted November 16, 2008 Author Share Posted November 16, 2008 thanks but we need to include the industries bec there are many more matches. can u include the industries pls Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691273 Share on other sites More sharing options...
JasonLewis Posted November 16, 2008 Share Posted November 16, 2008 So what exactly do you want to capture? The 51 and the 29.31? Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691277 Share on other sites More sharing options...
dtdetu Posted November 16, 2008 Author Share Posted November 16, 2008 i want to capture 29.31. but i am capturing this from a page that contains more matches thats why i want to include industries. Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691279 Share on other sites More sharing options...
ddrudik Posted November 16, 2008 Share Posted November 16, 2008 if(preg_match("~<td>Industries</td>\s*<td>[^<]*</td>\s*<td>([^<]*)</td>~i", $string, $result)){ $result = $result{1]; echo $result; } Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691291 Share on other sites More sharing options...
dtdetu Posted November 16, 2008 Author Share Posted November 16, 2008 thank you ddrudik thats what i need . Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.