Jump to content

Extracting date from HTML code.


virtuexru

Recommended Posts

OK PHP Gurus, another question :). I'm really struggling to get this down pact so I'm sorry if my questions are redundant. Just trying to get things to work :-P.

 

Here is the HTML code I have:

 

<td align="right">Sale Date :</td>

		<td align="LEFT" colspan="2">	




1/26/09

</td>

 

My goal is to EXTRACT the date "1/26/09" (could be ANY date at ANY given time, so basically its always unique) into a separate variable. How should I go about doing this?

 

I tried something like this but it didn't work:

 

// Find date
$pat = "%\A(?:^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}$)\Z%";
preg_match_all($pat, $data, $date);
print_r($date);

Link to comment
Share on other sites

try

<?php
$test = '<td align="right">Sale Date :</td>

		<td align="LEFT" colspan="2">	




1/02/09
01.28.1999
10*9.9/99=1
</td>';
$pat = '/[0\s]([1-9]|1[012])([- \/.])(0?[1-9]|[12][0-9]|3[01])\2((19|20)?[0-9][0-9])/';
preg_match_all($pat,$test,$out);
$out = $out[0];
foreach ($out as $k => $v) $out[$k] = trim($v);
print_r($out);
?>

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.