Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-31-2011, 05:35 PM   PM User | #1
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
Need help with a date function

I am scraping Birthdays from a webpage that are in this format
September 15, 1987

$age = 15;
$page = source code of a html page;

so far i have made this function

How do i return the function as true if the date scaped makes the person over 15 and false if the person is younger?

PHP Code:
function checkForAge($page,$age) {
  
preg_match('|Born on ([a-zA-Z]*\s[0-9]*,\s[0-9]*)\\\u003c\\\/span>|'$page$match);
    if(
$match && count($match)>0) {
        echo 
"Match Found";
        
$dateOfBirth str_replace(",","",$match[1]);
    
//    $dateOfBirth = date('d/m/Y', strtotime($dateOfBirth));
    
$dateOfBirth strtotime($dateOfBirth);
        
/*

       if("date of birth makes person over $age)
         {
          return true;
         }
       else 
        {
         return false;
         }
*/

    


Last edited by kevinkhan; 01-31-2011 at 05:42 PM..
kevinkhan is offline   Reply With Quote
Old 01-31-2011, 06:00 PM   PM User | #2
ecco
New Coder

 
Join Date: Dec 2010
Location: IA
Posts: 41
Thanks: 0
Thanked 4 Times in 4 Posts
ecco is an unknown quantity at this point
PHP Code:
/* get the birth year */
$birth_year strftime("%Y"strtotime($dateOfBirth));
/* get the current year */
$current_year strftime("%Y"strtotime("now"));

/* subtract birth_year from current_year to get age difference */
$calc_age $current_year $birth_year;

if(
$calc_age $age){
return 
true;
}
else{
return 
false;

also, remove $dateOfBirth = strtotime($dateOfBirth);

On second thought, this won't take into account the day of birth, only year. This may or may not be good enough.

Last edited by ecco; 01-31-2011 at 06:18 PM.. Reason: this is pretty crude and probably won't work
ecco is offline   Reply With Quote
Users who have thanked ecco for this post:
kevinkhan (01-31-2011)
Old 01-31-2011, 08:31 PM   PM User | #3
kevinkhan
Regular Coder

 
Join Date: Jun 2009
Posts: 350
Thanks: 75
Thanked 0 Times in 0 Posts
kevinkhan is an unknown quantity at this point
Quote:
Originally Posted by ecco View Post
PHP Code:
/* get the birth year */
$birth_year strftime("%Y"strtotime($dateOfBirth));
/* get the current year */
$current_year strftime("%Y"strtotime("now"));

/* subtract birth_year from current_year to get age difference */
$calc_age $current_year $birth_year;

if(
$calc_age $age){
return 
true;
}
else{
return 
false;

also, remove $dateOfBirth = strtotime($dateOfBirth);

On second thought, this won't take into account the day of birth, only year. This may or may not be good enough.

Thanks that worked
kevinkhan is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:30 PM.


Advertisement
Log in to turn off these ads.