Jump to content

Turn Tables into an Array


uancletus

Recommended Posts

I am looking to parse a table efficiently into an array with PHP.

I need the array to have this data:

$example[$channel_id]['users'] // array of users for that channel, false if empty
$example[$channel_id]['name'] // name of channel
$example[$channel_id]['locked'] // boolean of whether or not it is locked

 

I figure it might be easy to do by exploding by \n and then just run through each part of the array and figure out where it would go with strpos.

 

The problem is, I do not know how I would go about doing it through an unknown amount of nesting. Can anyone help?

 

Here is the exact structure, the same structure is the same, just sometimes more channels or more users, etc.:

<table width="95%" border="0">
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="servericon.png" align="absmiddle"></img><strong>ROOT CHANNEL</strong></div><table width="95%" border="0" align="right">
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="user.png" align="absmiddle"></img>USER1</div></td></tr>
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="lockedchannel.png" align="absmiddle"></img><strong>LOCKED CHANNEL</strong></div><table width="95%" border="0" align="right">
</table></td></tr>
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="openchannel.png" align="absmiddle"></img><strong>CHANNEL 1</strong></div><table width="95%" border="0" align="right">
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="user.png" align="absmiddle"></img>USER2</div></td></tr>
</table></td></tr>
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="channel.png" align="absmiddle"></img><strong>CHANNEL 2</strong></div><table width="95%" border="0" align="right">
</table></td></tr>
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="openchannel.png" align="absmiddle"></img><strong>CHANNEL 3</strong></div><table width="95%" border="0" align="right">
<tr><td><div style="overflow:hidden;text-overflow:ellipsis"><img src="channel.png" align="absmiddle"></img><strong>NESTED CHANNEL 1</strong></div><table width="95%" border="0" align="right">
</table></td></tr>
</table></td></tr>
</table>
</table>

Link to comment
https://forums.phpfreaks.com/topic/180918-turn-tables-into-an-array/
Share on other sites

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.