Jump to content

Recommended Posts

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 :)

 

 

 

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]);
?> 

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]);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.