Jump to content

Loop -> extract -> insert to db


drisate

Recommended Posts

Hey guys ... i need to create a PHP scripts that literly scans a board post to extract the username and time of the post then store them to the database

 

1 post looks like this

 

<table cellpadding="4" cellspacing="1" border="0" style="width:100%" class="tableinborder">
<tr align="left">
	<td class="tablea" valign="top"><a name="post6794327" id="post6794327">
	</a>
	<table style="width:100%" cellpadding="4" cellspacing="0" border="0" class="tablea_fc">
		<tr>
			<td style="width:100%" class="smallfont">
			<span class="normalfont"><b>
			<a href="profile.php?userid=106475" style="color: #B0C4DE; text-decoration: none">
			Beaster</a></b></span> <br />
			Recycler <br />
			<img src="en_images_ogame/star.gif" border="0" alt="" title /><img src="en_images_ogame/star.gif" border="0" alt="" title /><img src="en_images_ogame/star.gif" border="0" alt="" title /><img src="en_images_ogame/star.gif" border="0" alt="" title /><img src="en_images_ogame/star.gif" border="0" alt="" title />
			<br />
			<br />
			<img src="images/avatars/avatar-63671.jpg" border="0" alt="images/avatars/avatar-63671.jpg" title /><br />
			<br />
			Registration Date: 06-02-2008<br />
			Posts: 166<br />
			Location: Quebec in Canada<br />
			Universe: 1<br />
			Alliance: Dramis<br />
			<br />
			<img src="en_images_ogame/spacer.gif" width="159" height="1" border="0" alt="" title /></td>
		</tr>
	</table>
	</td>
	<td class="tablea" valign="top" style="width:100%">
	<table style="width:100%" cellpadding="4" cellspacing="0" border="0" class="tablea_fc">
		<tr>
			<td style="width:100%" class="normalfont" align="left">
			<table style="width:100%" cellpadding="4" cellspacing="0" border="0" class="tablea_fc">
				<tr>
					<td><span class="smallfont"><b>DC.UA VS Phoenix</b></span></td>
					<td align="right" nowrap="nowrap">
					<a href="addreply.php?postid=6794327" style="color: #B0C4DE; text-decoration: none">
					<img src="en_images_ogame/replypost.gif" border="0" alt="Reply to this Post" title="Reply to this Post" /></a>
					<a href="addreply.php?action=quote&postid=6794327" style="color: #B0C4DE; text-decoration: none">
					<img src="en_images_ogame/quote.gif" border="0" alt="Post Reply with Quote" title="Post Reply with Quote" /></a>
					<a href="editpost.php?postid=6794327" style="color: #B0C4DE; text-decoration: none">
					<img src="en_images_ogame/editpost.gif" border="0" alt="Edit/Delete Posts" title="Edit/Delete Posts" /></a>
					<a href="report.php?postid=6794327" style="color: #B0C4DE; text-decoration: none">
					<img src="en_images_ogame/report.gif" border="0" alt="Report Post to a Moderator" title="Report Post to a Moderator" /></a>       
					<a href="javascript:self.scrollTo(0,0);" style="color: #B0C4DE; text-decoration: none">
					<img src="en_images_ogame/goup.gif" border="0" alt="Go to the top of this page" title="Go to the top of this page" /></a></td>
				</tr>
			</table>
			<hr size="1" class="threadline" />CRs Only <br />
			<br />
			__________________<br />
			<span style="font-size: 10px;">
			<img src="http://f-fr.com/newbk1_500.png" alt="" border="0" class="resizeImage" /></span><br />
			<br />
			Take a look at my Ogame Video&#39;s!<br />
			DC News -
			<a href="http://youtube.com/user/DramisC" target="_blank" style="color: #B0C4DE; text-decoration: none">
			http://youtube.com/user/DramisC</a><br />
			</td>
		</tr>
	</table>
	</td>
</tr>
<tr>
	<td class="tablea" align="center" nowrap="nowrap">
	<span class="smallfont">
	<a href="thread.php?postid=6794327#post6794327" style="color: #B0C4DE; text-decoration: none">
	<img src="en_images_ogame/posticon.gif" border="0" alt="" title /></a> 08-20-2008
	<span class="time">19:14</span></span></td>
	<td class="tablea" align="left" style="width:100%" valign="middle">
	<span class="smallfont">
	<img src="en_images_ogame/user_online.gif" border="0" alt="Beaster is online" title="Beaster is online" />
	<a href="mailto:[email protected]" style="color: #B0C4DE; text-decoration: none">
	<img src="en_images_ogame/email.gif" border="0" alt="Send an Email to Beaster" title="Send an Email to Beaster" /></a>
	<a href="http://f-fr.com/2" target="_blank" style="color: #B0C4DE; text-decoration: none">
	<img src="en_images_ogame/www.gif" border="0" alt="Homepage of Beaster" title="Homepage of Beaster" /></a>
	<a href="search.php?action=user&userid=106475" style="color: #B0C4DE; text-decoration: none">
	<img src="en_images_ogame/search.gif" border="0" alt="Search for Posts by Beaster" title="Search for Posts by Beaster" /></a>
	<a href="usercp.php?action=buddy&add=106475" style="color: #B0C4DE; text-decoration: none">
	<img src="en_images_ogame/homie.gif" border="0" alt="Add Beaster to your Buddy List" title="Add Beaster to your Buddy List" /></a>
	<a href="pms.php?action=newpm&userid=106475" style="color: #B0C4DE; text-decoration: none">
	<img src="en_images_ogame/pm.gif" border="0" alt="Send a Private Message to Beaster" title="Send a Private Message to Beaster" /></a>
	</span></td>
</tr>
</table>

 

I gave a basic idea of what the regex code to extract the value of 1 post would look like

 

  $txt='<a href="profile.php?userid=106475">Beaster</a>';

  $re1='.*?';	# Non-greedy match on filler
  $re2='(Beaster)';	# Variable Name 1

  if ($c=preg_match_all ("/".$re1.$re2."/is", $txt, $matches))
  {
      $var1=$matches[1][0];
      print "($var1) \n";
  }

 

and

 

  $txt='08-20-2008 <span class="time">19:14</span>';

  $re1='((?:[0]?[1-9]|[1][012])[-:\\/.](??:[0-2]?\\d{1})|(?:[3][0,1]{1}))[-:\\/.](??:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3})))(?![\\d])';	# MMDDYYYY 1
  $re2='.*?';	# Non-greedy match on filler
  $re3='((??:[0-1][0-9])|(?:[2][0-3])|(?:[0-9]))?:[0-5][0-9])(?::[0-5][0-9])?(?:\\s?(?:am|AM|pm|PM))?)';	# HourMinuteSec 1

  if ($c=preg_match_all ("/".$re1.$re2.$re3."/is", $txt, $matches))
  {
      $mmddyyyy1=$matches[1][0];
      $time1=$matches[2][0];
      print "($mmddyyyy1) ($time1) \n";
  }

 

But how can i make it loop every messages then perform the per thread extraction (username) then (Post time)

Link to comment
https://forums.phpfreaks.com/topic/146770-loop-extract-insert-to-db/
Share on other sites

Ok i have been able to pin point what i need ...

 

Can you help me build the regex to load the content for the stuff betwee

<table cellpadding="0" cellspacing="0" border="0" style="width:100%"><tr><td width="100%"><table cellpadding="4" cellspacing="1" border="0" style="width:100%" class="tableinborder">

 

and

</table></td></tr></table>

 

Then i can do a foreach loop and use my othe codes

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.