Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/181373-extract-values-from-html-table/
Share on other sites

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

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.