erezep Posted August 28, 2008 Share Posted August 28, 2008 Hello, i have a a page with a few html tables, i'm trying to match a specific tables that has some string in it. sample page: <HTML> <HEAD> </HEAD> <body> <table align="center" width="771" height="166" border="0" cellpadding="0" cellspacing="0"> <tr> first</tr> <tr> second</tr> </table> <table> <tr>matchthis</tr> </table> </BODY> </HTML> i'm using this regex: <table.+>.+>matchthis<.+<\/table> and i want to get only the latter table : <table> <tr>matchthis</tr> </table> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/121713-matching-specific-table-using-preg_match/ Share on other sites More sharing options...
effigy Posted August 28, 2008 Share Posted August 28, 2008 <pre> <?php $data = <<<DATA <HTML> <HEAD> </HEAD> <body> <table align="center" width="771" height="166" border="0" cellpadding="0" cellspacing="0"> <tr> first</tr> <tr> second</tr> </table> <table> <tr>matchthis</tr> </table> </BODY> </HTML> DATA; preg_match('%<table[^>]*>(??!</table>).)*?matchthis.*?</table>%s', $data, $matches); print_r(htmlspecialchars($matches[0])); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/121713-matching-specific-table-using-preg_match/#findComment-627876 Share on other sites More sharing options...
erezep Posted August 28, 2008 Author Share Posted August 28, 2008 Thanks works like a charm i have been struggling with it for a few days. Quote Link to comment https://forums.phpfreaks.com/topic/121713-matching-specific-table-using-preg_match/#findComment-627903 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.