uancletus Posted November 10, 2009 Share Posted November 10, 2009 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 More sharing options...
uancletus Posted November 10, 2009 Author Share Posted November 10, 2009 Is it even possible to do this? Link to comment https://forums.phpfreaks.com/topic/180918-turn-tables-into-an-array/#findComment-954969 Share on other sites More sharing options...
Adam Posted November 10, 2009 Share Posted November 10, 2009 Rather than trying to manually explode and substr/strpos/strstr or anything like that, you'd probably have much better luck using the DOM extension. Link to comment https://forums.phpfreaks.com/topic/180918-turn-tables-into-an-array/#findComment-954982 Share on other sites More sharing options...
uancletus Posted November 10, 2009 Author Share Posted November 10, 2009 I'm not quite sure how to use the DOM() extension, do you have any decent examples? Link to comment https://forums.phpfreaks.com/topic/180918-turn-tables-into-an-array/#findComment-955199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.