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; Quote 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]; Quote 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 Quote 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? Quote 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. Quote 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; } Quote 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 . Quote Link to comment https://forums.phpfreaks.com/topic/132934-solved-easy-regex-question/#findComment-691303 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.