Jump to content

From an array output, print only after line X


thales.pereira

Recommended Posts

Hello again

 

I was trying to solve this by myself and again im struggling on this apparently simple regex.

 

For now i have the code bellow, with the following code:

$html_c2 = file_get_contents("http://somehost");
print_r($html_c2);  

 

With the following output:

--------OUTPUT---------

<BODY bgcolor=#dddddd>
<TABLE bgcolor=#dddddd border=1>
<TR>
<TD valign=top><B>acl</B></TD>
<TD>ACL</TD>
</TR>
<TR>
<TD valign=top><B>aclList</B></TD>
<TD>
<TABLE>
<TR>
<TD>ACL</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD valign=top><B>nameList</B></TD>
<TD>
<TABLE>
</TABLE>
</TD>
</TR>
</TABLE>
</BODY>
<BODY bgcolor=#dddddd>
<TABLE bgcolor=#dddddd border=1>
<TR>
<TD valign=top><B>acl</B></TD>
<TD>Administrators</TD>
</TR>
<TR>
<TD valign=top><B>aclList</B></TD>
<TD>
<TABLE>
<TR>
<TD>Administrators</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD valign=top><B>nameList</B></TD>
<TD>
<TABLE>
<TR>
<TD>wm.server</TD>
</TR>
<TR>
<TD>wm.server.dispatcher.adminui</TD>
</TR>
<TR>
<TD>wm.server.ports:listListeners</TD>
</TR>
<TR>

 

What im searching for, is print everyline after the field nameList. until now, i had two ideas:

 

 

1)

using the code bellow to retrieve all lines that have <TD> , but need to print all lines after the line 4 of the array

$html_c2 = file_get_contents("http://somehost");     

preg_match_all('/<TD>.*/', $html_c2, $acl_c2);

print_r($acl_c2);

 

---current ouput----

Array
(
    [0] => Array
        (
            [0] => <TD>Administrators</TD>
            [1] => <TD>
            [2] => <TD>Administrators</TD>
            [3] => <TD>
            [4] => <TD>wm.server</TD>
            [5] => <TD>wm.server.dispatcher.adminui</TD>
            [6] => <TD>wm.server.ports:listListeners</TD>
            [7] => <TD>wm.server.replicator</TD>
            [8] => <TD>wm.server.replicator.adminui</TD>
            [9] => <TD>wm.server.net.listeners</TD>
many more lines....

 

Desired output

Array
(
    [0] => Array
        (
            [1] => wm.server
            [2] => wm.server.dispatcher.adminui
            [3] => wm.server.ports:listListeners
            [4] => wm.server.replicator
            [5] => wm.server.replicator.adminui
            [6] => wm.server.net.listeners
many more lines....

 

 

2) Using strip tags, to remove html tags, but im unable to discover how i can get rid of the whitespaces, and get the output after the Field nameList

      $html_c2 = strip_tags(file_get_contents("http://somehost"));

      print_r($html_c2);

 

--Current output--

 




acl
ACL


aclList



ACL





nameList










acl
Administrators


aclList



Administrators





nameList



wm.server

wm.server.dispatcher.adminui



wm.server.ports:listListeners


wm.server.replicator


wm.server.replicator.adminui


wm.server.net.listeners

 

Desired output:

 

wm.server
wm.server.dispatcher.adminui
wm.server.ports:listListeners
wm.server.replicator
wm.server.replicator.adminui
wm.server.net.listeners

 

I dont know wich idea could be faster or easier, but is what i had in mind until now... If anyone have a solution for this, would be great.

 

 

thanks all for at least looking into it :)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.