thernes Posted November 13, 2009 Share Posted November 13, 2009 Hi guys I am a total noob with php and this one has got me stubled. I have the following table; <table border="2" cellspacing="0" cellpadding="2"><tr><td><b>Account-ID</b></td><td><b>Password</b></td><td><b>E-Mail</b></td><td><b>Add time</b></td><td><b>Fraud</b></td><td><b>Valid until</b></td><td><b>AED</b></td></tr> <tr><td>11111111</td><td>00000000</td><td></td><td>2009-11-13 08:30:01</td><td><font color="green">No</font></td><td>2009-12-13 08:30:01</td><td>21</td></tr> </table> From this I would like to extract the Account ID value and the password so that I can insert these into a database, so that $username would equal 11111111 in this case and $password would equal 00000000. This is what I have come up with so far, but is seems to be way off; $searchstring = '<table border="2" cellspacing="0" cellpadding="2"><tr><td><b>Account-ID</b></td><td><b>Password</b></td><td><b>E-Mail</b></td><td><b>Add time</b></td><td><b>Fraud</b></td><td><b>Valid until</b></td><td><b>AED</b></td></tr>'; $pos1 = strpos($data,$searchstring); $length = strlen($searchstring); $data = substr($data,$pos1+$length); $data = trim($data); $newaccountid = substr($data,8,; Thanks for helping out a noob! T Quote Link to comment https://forums.phpfreaks.com/topic/181373-extract-values-from-html-table/ Share on other sites More sharing options...
JonnoTheDev Posted November 13, 2009 Share Posted November 13, 2009 <?php $table = '<table border="2" cellspacing="0" cellpadding="2"> <tr> <td><b>Account-ID</b></td> <td><b>Password</b></td> <td><b>E-Mail</b></td> <td><b>Add time</b></td> <td><b>Fraud</b></td> <td><b>Valid until</b></td> <td><b>AED</b></td> </tr> <tr> <td>11111111</td> <td>00000000</td> <td></td> <td>2009-11-13 08:30:01</td> <td><font color="green">No</font></td> <td>2009-12-13 08:30:01</td> <td>21</td> </tr> </table>'; function parseArray($string, $openTag, $closeTag) { preg_match_all("($openTag(.*)$closeTag)siU", $string, $matches); return $matches[0]; } $trArray = parseArray($table, "<tr>", "</tr>"); if(count($trArray)) { $tdArray = parseArray($trArray[1], "<td>", "</td>"); // display data print "Username: ".strip_tags($tdArray[0])."<br />"; print "Password: ".strip_tags($tdArray[1]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181373-extract-values-from-html-table/#findComment-956774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.