sonal4php Posted February 8, 2007 Share Posted February 8, 2007 i want to retrieve certain elements bound in same format in an html file. i have lot much raw data in this html file, i have stored this in string =$data and i am looking for such pattern: <td width='15%' valign=top>41 </td> among which 41 is desired result. note: 15% is not constant it can be 15%,25% and 35% i have many rows like this in html file, and i want to pick the same value which is bound in <td width='15%' valign=top> and </td> i am trying this code: preg_match_all("|<[td width='[0-9]{1}5%' valign=top>]+>(.*)</[/td>]+>|U",$data,$out,PREG_PATTERN_ORDER); print_r($out[1]); but i am not getting desired result can someone please help.... thanx Link to comment https://forums.phpfreaks.com/topic/37627-preg_match_all-for-html-tags/ Share on other sites More sharing options...
effigy Posted February 8, 2007 Share Posted February 8, 2007 [...] is a character class which does not match a sequence of characters, but individual characters. <pre> <?php $string = "<td width='15%' valign=top>41 </td>"; preg_match_all("/<td width='\d+%' valign=top>(\d+)/", $string, $out); print_r($out[1][0]); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/37627-preg_match_all-for-html-tags/#findComment-180013 Share on other sites More sharing options...
sonal4php Posted February 8, 2007 Author Share Posted February 8, 2007 thanx a lot i will test the same in my code Link to comment https://forums.phpfreaks.com/topic/37627-preg_match_all-for-html-tags/#findComment-180210 Share on other sites More sharing options...
sonal4php Posted February 9, 2007 Author Share Posted February 9, 2007 hi, i am trying a lil different code in regex on the same logic $string="get data(s):</td><td><em>MY DATA</em>"; preg_match_all("/get data(s):</td><td><em>(.*)</em>/", $string, $out); print_r($out); i want to pick "MY DATA" but this isn't permits /td and /em in pattern.. what's the solution.. and can u please suggest some easy to learn regex tutorial... thanx Link to comment https://forums.phpfreaks.com/topic/37627-preg_match_all-for-html-tags/#findComment-180878 Share on other sites More sharing options...
effigy Posted February 9, 2007 Share Posted February 9, 2007 See this topic for more information on your error. PHP Freaks: Introduction to regular expressions (#1): General Mechanics Regular Expression Tutorial Link to comment https://forums.phpfreaks.com/topic/37627-preg_match_all-for-html-tags/#findComment-180916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.