thales.pereira Posted March 7, 2011 Share Posted March 7, 2011 Hello everyone, Im new on regex and im blocking my brain with this one... i have a php file wich extract an html page seeking for every entry which is located bellow the tag <TD valign="top"><B>name</B></TD> for example: <TD valign="top"><B>name</B></TD> <TD>Administrators</TD> </TR> <TR> <TD valign="top"><B>inUse</B></TD> <TD>true</TD> </TR> <TR> <TD valign="top"><B>allow</B></TD> <TD valign="top"><B>name</B></TD> <TD>Users</TD> </TR> <TR> <TD valign="top"><B>inUse</B></TD> <TD>true</TD> </TR> <TR> <TD valign="top"><B>allow</B></TD> <TD valign="top"><B>name</B></TD> <TD>Developers</TD> </TR> <TR> <TD valign="top"><B>inUse</B></TD> <TD>true</TD> </TR> <TR> <TD valign="top"><B>allow</B></TD> Until now, im only able seek the lines with: $html = strip_tags(file_get_contents("http://$iUser:$iPass@$iHost/invoke/wm.server.access/aclList")); preg_match_all('/(name.*\n.*)/', substr($html,3), $matches); print_r ($matches) ##### OUTPUT ###### Array ( [ 0 ] => Array ( [ 0 ] => name Administrators [ 1 ] => name Users [ 2 ] => name Developers ) ) but... my desirable output is: ##### OUTPUT ###### Array ( [ 0 ] => Array ( [ 0 ] => Administrators [ 1 ] => Users [ 2 ] => Developers ) ) If anyone could help on this, im paying a virtual beer Link to comment https://forums.phpfreaks.com/topic/229885-print-line-after-pattern-but-not-the-pattern/ Share on other sites More sharing options...
sasa Posted March 7, 2011 Share Posted March 7, 2011 try <?php $test = '<TD valign="top"><B>name</B></TD> <TD>Administrators</TD> </TR> <TR> <TD valign="top"><B>inUse</B></TD> <TD>true</TD> </TR> <TR> <TD valign="top"><B>allow</B></TD> <TD valign="top"><B>name</B></TD> <TD>Users</TD> </TR> <TR> <TD valign="top"><B>inUse</B></TD> <TD>true</TD> </TR> <TR> <TD valign="top"><B>allow</B></TD> <TD valign="top"><B>name</B></TD> <TD>Developers</TD> </TR> <TR> <TD valign="top"><B>inUse</B></TD> <TD>true</TD> </TR> <TR> <TD valign="top"><B>allow</B></TD>'; preg_match_all('/<TD valign="top"><B>name<\/B><\/TD>.*?<TD>([^<]+)<\/TD>/is', $test, $out); print_r($out[1]); ?> Link to comment https://forums.phpfreaks.com/topic/229885-print-line-after-pattern-but-not-the-pattern/#findComment-1184158 Share on other sites More sharing options...
silkfire Posted March 7, 2011 Share Posted March 7, 2011 Sure do. Your results are in $matches[1], remember that. $matches[0] is the full captured pattern, including characters you don't want. I tried your regex and it doesn't seem to work so I changed it a a litte. Also you don't need to strip tags before regex, do it after. Try to print_r the array now. $html = file_get_contents("http://$iUser:$iPass@$iHost/invoke/wm.server.access/aclList"); preg_match_all('#name</B></TD>\s<td>([^<]+)#i', $html, $matches); print_r($matches[1]); Link to comment https://forums.phpfreaks.com/topic/229885-print-line-after-pattern-but-not-the-pattern/#findComment-1184159 Share on other sites More sharing options...
thales.pereira Posted March 9, 2011 Author Share Posted March 9, 2011 Thank you both for the reply. it worked like a charm Link to comment https://forums.phpfreaks.com/topic/229885-print-line-after-pattern-but-not-the-pattern/#findComment-1184972 Share on other sites More sharing options...
silkfire Posted March 9, 2011 Share Posted March 9, 2011 Which solution did you end up with? Link to comment https://forums.phpfreaks.com/topic/229885-print-line-after-pattern-but-not-the-pattern/#findComment-1184995 Share on other sites More sharing options...
thales.pereira Posted March 9, 2011 Author Share Posted March 9, 2011 I tested yours first. Since it worked, i didn't tried the first suggestion by sasa. Link to comment https://forums.phpfreaks.com/topic/229885-print-line-after-pattern-but-not-the-pattern/#findComment-1184998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.