Jump to content

[SOLVED] Need help :) pregmatch


IvanPeso

Recommended Posts

Hey there,

 

I am not so experienced in this area of PHP so I need very big help

 

With cURL i login to 1 website and get content of that website on my site . In that content there is this table (under this text) for every player that is on server code looks like this

	<tr align="left"><td align="center"><input class="checkbox" type='checkbox' name='Kick5' value='True'>

</td>
<td align="center"><input class="checkbox" type='checkbox' name='Ban5' value='True'>

</td>
<td align="left" nowrap>FireX</td>
<td align="center" nowrap><span style='background-color: Blue'>  </span>Blue</td>
<td align="center">48</td>
<td align="center">0</td>
<td align="center"> 89.164.221.222</td>
<td align="center"> 5h600ez07dcda5a64685985d955c1552</td>
</tr>

In that code i need to select "Kick5" (from that input on the beginning of code but it can be Kick13 or something like that Kick5 is just example).

Then i need to select "FireX" that is always put between <td align="left" nowrap> and </td>, then need to select this "89.164.221.222" it is aways between <td align="center">  and </td> and I need to select "5h600ez07dcda5a64685985d955c1552" witch is always between <td align="center">  and </td> an write this down to mysql database. I know how to make database code so you don't need to do it just leave place for that code (comment it somehow).

 

Script needs to do it for every player (that means every time when that code on top appears). I already made code for getting code from that web site

 

Thanks for help . I am trying to make this code for almost 1 week and not going very well ...

 

Cheers Ivan

Link to comment
Share on other sites

try this

<?php
$html = <<<EOD
      <tr align="left"><td align="center"><input class="checkbox" type='checkbox' name='Kick5' value='True'>

</td>
<td align="center"><input class="checkbox" type='checkbox' name='Ban5' value='True'>

</td>
<td align="left" nowrap>FireX</td>
<td align="center" nowrap><span style='background-color: Blue'>  </span>Blue</td>
<td align="center">48</td>
<td align="center">0</td>
<td align="center"> 89.164.221.222</td>
<td align="center"> 5h600ez07dcda5a64685985d955c1552</td>
</tr>
EOD;

if (preg_match('%<tr align="left"><td align="center"><input class="checkbox" type=\'checkbox\' name=\'([^\']*)\' value=\'True\'>.*?<td align="left" nowrap>([^<]*)</td>.*?<td align="center"> ([^<]*)</td>\s*<td align="center"> ([^<]*)</td>%sm', $html, $regs)) {
$name = $regs[1];
$group = $regs[2];
$ip = $regs[3];
$hash = $regs[4];
}
echo "$name, $group, $ip, $hash<br>";
?>

Link to comment
Share on other sites

So more like this

<?php
$html = <<<EOD
      <tr align="left"><td align="center"><input class="checkbox" type='checkbox' name='Kick5' value='True'>

</td>
<td align="center"><input class="checkbox" type='checkbox' name='Ban5' value='True'>

</td>
<td align="left" nowrap>FireX</td>
<td align="center" nowrap><span style='background-color: Blue'>  </span>Blue</td>
<td align="center">48</td>
<td align="center">0</td>
<td align="center"> 89.164.221.222</td>
<td align="center"> 5h600ez07dcda5a64685985d955c1552</td>
</tr>

      <tr align="left"><td align="center"><input class="checkbox" type='checkbox' name='Kick99' value='True'>

</td>
<td align="center"><input class="checkbox" type='checkbox' name='Ban5' value='True'>

</td>
<td align="left" nowrap>FdfdsfsdfireX</td>
<td align="center" nowrap><span style='background-color: Blue'>  </span>Blue</td>
<td align="center">48</td>
<td align="center">0</td>
<td align="center"> 89.155.221.222</td>
<td align="center"> 5h600ez07dcgfjh5985d955c1552</td>
</tr>

      <tr align="left"><td align="center"><input class="checkbox" type='checkbox' name='MadTechie' value='True'>

</td>
<td align="center"><input class="checkbox" type='checkbox' name='Ban5' value='True'>

</td>
<td align="left" nowrap>Fire111</td>
<td align="center" nowrap><span style='background-color: Blue'>  </span>Blue</td>
<td align="center">48</td>
<td align="center">0</td>
<td align="center"> 89.164.221.222</td>
<td align="center"> 5h600eBLAR64685985d955c1552</td>
</tr>
EOD;

preg_match_all('%<tr align="left"><td align="center"><input class="checkbox" type=\'checkbox\' name=\'([^\']*)\' value=\'True\'>.*?<td align="left" nowrap>([^<]*)</td>.*?<td align="center"> ([^<]*)</td>\s*<td align="center"> ([^<]*)</td>%sm', $html, $players, PREG_SET_ORDER);
foreach($players as $player)
{
list($void, $name, $group, $ip, $hash) = $player;
echo "$name, $group, $ip, $hash<br>\n";
}
?>

Link to comment
Share on other sites

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.