RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Find a Zodiac Sign by Birthdate with PHP

Here's some very simple code that'll determine a Zodiac sign given a birthdate. If I've screwed up on dates, let me know.

1
<?php 
2
/*
3
 Find a Zodiac Sign by Birthdate with PHP
4
 http://www.beliefmedia.com/code/php-snippets/zodiac-sign
5
*/
6
 
7
function beliefmedia_zodiac($birthdate) {
8
 
9
   $zodiac = '';
10
   list ($year, $month, $day) = explode ('-', $birthdate);
11
 
12
   if ( ( $month == 3 && $day > 20 ) || ( $month == 4 && $day < 20 ) ) { $zodiac = "Aries"; }
13
   elseif ( ( $month == 4 && $day > 19 ) || ( $month == 5 && $day < 21 ) ) { $zodiac = "Taurus"; }
14
   elseif ( ( $month == 5 && $day > 20 ) || ( $month == 6 && $day < 21 ) ) { $zodiac = "Gemini"; }
15
   elseif ( ( $month == 6 && $day > 20 ) || ( $month == 7 && $day < 23 ) ) { $zodiac = "Cancer"; }
16
   elseif ( ( $month == 7 && $day > 22 ) || ( $month == 8 && $day < 23 ) ) { $zodiac = "Leo"; }
17
   elseif ( ( $month == 8 && $day > 22 ) || ( $month == 9 && $day < 23 ) ) { $zodiac = "Virgo"; }
18
   elseif ( ( $month == 9 && $day > 22 ) || ( $month == 10 && $day < 23 ) ) { $zodiac = "Libra"; }
19
   elseif ( ( $month == 10 && $day > 22 ) || ( $month == 11 && $day < 22 ) ) { $zodiac = "Scorpio"; }
20
   elseif ( ( $month == 11 && $day > 21 ) || ( $month == 12 && $day < 22 ) ) { $zodiac = "Sagittarius"; }
21
   elseif ( ( $month == 12 && $day > 21 ) || ( $month == 1 && $day < 20 ) ) { $zodiac = "Capricorn"; }
22
   elseif ( ( $month == 1 && $day > 19 ) || ( $month == 2 && $day < 19 ) ) { $zodiac = "Aquarius"; }
23
   elseif ( ( $month == 2 && $day > 18 ) || ( $month == 3 && $day < 21 ) ) { $zodiac = "Pisces"; }
24
 
25
 return $zodiac;
26
}
27
[/php]
28
 
29
<strong>Usage:</strong>
30
[php]$birthdate = "2013-12-20";
31
echo beliefmedia_zodiac($birthdate);

When we posted this on Internoetics we had a number of comments - most of them relating to the date grouping.

Date Formats

For an 8-figure time-group (20131220), YYYYMMDD, remove the following line:

1
list ($year, $month, $day) = explode ("-", $birthdate);

... and use the following:

1
<?php 
2
$date = '20131220';
3
 
4
/* Format yyyymmdd */
5
preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})/', $date, $matches);
6
 
7
$month = $matches['2'];
8
 $month = ltrim($month, '0');
9
$day = $matches['3'];
10
 $day = ltrim($day, '0');

You could also use PHP's str_split as an alternative the preg_match. Using str_split($date, 2); will split a string into an array with the values having a length of 2 characters. Remember, it's only the two-figure day and month that we're after.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment