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
https://forums.phpfreaks.com/topic/141807-extracting-date-from-html-code/
Share on other sites

OK, so far I have also tried this, it looks like it should work but I'm getting an output of just some blank arrays.

 

<?

// Find date
$pattern = '#^(\d{1,2})[/-](\d{1,2})[/-](\d{4})$#';
preg_match_all($pattern, $data, $date);
// Print
print_r($date);

?>

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

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.