Friday, August 14, 2015

How to check a dates of a date range lies in between two dates in PHP & mysql query?

I have a date range like
date from=2011-10-14 & date to=2011-10-20
if I have another date ranges
- 2011-10-11 - 2011-10-15
- 2011-10-11 - 2011-10-21
- 2011-10-15 - 2011-10-21
- 2011-10-15 - 2011-10-19
- 2011-10-21 - 2011-10-26
date_from < ‘2011-10-20’ AND date_to > '2011-10-14’
WHERE date_from >= '2011-10-14’ AND date_to <= '2011-10-20’

How to Return all dates between two dates in an array?

Expected Input:
getDatesFromRange( ‘2010-10-01’, '2010-10-05’ );
Expected Output:
Array( '2010-10-01’, '2010-10-02’, '2010-10-03’, '2010-10-04’, '2010-10-05’ )
function createDateRangeArray($strDateFrom,$strDateTo)
   // takes two dates formatted as YYYY-MM-DD and creates an
   // inclusive array of the dates between the from and to dates.
   // could test validity of dates here but I’m already doing
   // that in the main script
   $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
   $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));
   if ($iDateTo>=$iDateFrom)
       array_push($aryRange,date('Y-m-d’,$iDateFrom)); // first entry
       while ($iDateFrom<$iDateTo)
           $iDateFrom+=86400; // add 24 hours
   return $aryRange;

How to Display MySQL Dates in Other Formats using PHP?

How to insert and show dates in different format?
public function input_date($date)
$c_date = explode(“/”,$date);
$form_date = $c_date[2].’-’.$c_date[1].’-’.$c_date[0];

public function show_date($date)
$c_date = explode(“-”,$date);
$form_date = $c_date[2].’/’.$c_date[1].’/’.$c_date[0];
MySQL stores dates in the format YYYY-MM-DD… which is great, it’s consistent and easy to understand—If you happen to be a computer. Unfortunately, this format is rather confusing for humans, especially for humans which may be trying to communicate with individuals who read dates differently. For example, those of us in the US usually record the 10th of May in the year 2015 as 05/10/2015 whereas individuals in other countries often record the same date as 10/05/2015, causing considerable confusion in communication.
So what do we do to solve this? When in doubt, write it out! Here’s how to take a date retrieved from a MySQL database by PHP and convert it to an international human-friendly format.
We’ll first assume that you have retrieved your data into array $myrow. Say the date stored in MySQL is 2015-08-04. Here’s how to display it in various forms. Precede each of these by echo or print, whichever is appropriate for your application. All of these can be modified as needed by using the various formatting characters as described in the PHP.
Desired Text & their relevant Code:-
August 04, 2015
date("F d, Y",strtotime($myrow['date']));

Tuesday, August 04, 2015
date("l, F d, Y",strtotime($myrow['date']));

Aug 04, 2015
date("M d, Y",strtotime($myrow['date']));

04 August 2015
date("d F Y",strtotime($myrow['date']));

04 Aug 2015
date("d M Y",strtotime($myrow['date']));

Tue, 04 Aug 2015
date("D, d M Y",strtotime($myrow['date']));

Tuesday, the 4th of August, 2015
date("l",strtotime($myrow['date'])) . ", the " . date("jS",strtotime($myrow['date'])) . " of " . date("F, Y",strtotime($myrow['date']));

How to find the difference between two dates using php?

Here’s the code snippet to find the difference between two dates:-
$date1 = “2009-01-01 00:00:00”;
$date2 = “2010-03-21 14:34:09”;
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24) / (60*60*24));
$hours   = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24)/ (60*60));
$minutes  = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60)/ 60);
$seconds = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24 - $days*60*60*24 - $hours*60*60 - $minutes*60));
echo $years.“ years, ”.$months.“ months, ”.$days.“ days, ”.$hours.“ hours, ”.$minutes.“ minutes, ”.$seconds.“ seconds”;

PHP - String function explanation

All String Functions in PHP:-
  1. str_replace: How to replace a part of a string with another string
  2. str_ireplace: Case in-sensitive search and replace using array of strings
  3. strlen: How to find length of a string in PHP?
  4. trim: Removing empty space from both sides of a string
  5. strrev: Reversing a string by using strrev function in PHP
  6. Adding two or more strings in PHP
  7. stristr: Searching for a presence of a string inside another string
  8. nl2br: Adding Line breaks inside a string in place of carriage returns
  9. split: Breaking a string to form array using delimiters
  10. substr: Collecting part of a string
  11. substr_count: Counting occurrence of sub string in main string
  12. str_repeat: Repeating a string number of times
  13. strtolower(): function to change alphabets to Lower case
  14. strtoupper(): function to change characters to upper case letters
  15. function to collect part of a string with two landmarks
  16. Random string generator with number and alphabets for password
  17. strcasecmp(): Case insensitive string comparison
  18. strcmp(): Case sensitive string comparison
  19. str_pad(): String pad with specified length
  20. md5 hash of a string: encryption of a string
  21. Separating domain and userid part from an email address using split
  22. htmlspecialchars: Printing html special chars to the page
  23. strip_tags: Removing html tags within a string
  24. ucwords: Converting first letter of every word to UpperCase

MySQL Table of all Countries

The below-linked MySQL script contains the ISO2, ISO3, ISO numerical codes, calling codes, and ccTLDs, as well as the short and long names for the countries shown below. I have endeavored to list all of the countries in the world, but I know I've missed some—any additions or corrections would be welcome! The zip file contains all of the flags shown below.

Note: The short names use only the letters found on a standard US QWERTY keyboard, while the long names use the HTML entities. the ISO codes and UN membership information is accurate as of April 2012. If you are aware of any changes to this data, any changes to the flags, or any errors, please let me know.

April 2012 update: I added ccTLD codes for every country that has them, updated several country names, renumbered some of the country_id OIDs (So if you are already using an earlier version of my country table on your website, do NOT just replace your existing data or you will mess it up!! New users won't have a problem.), eliminated at least one country that no longer exists (Netherlands Antilles), added another country that sort of exists (Kosovo), updated the flag images, and added more calling codes and corrected others. Finally, I also created an add-on script to add country names in Spanish to the script, for those that may need them (it's not part of the main script, click on the link to get the script you need to add them). All data is accurate as of 7 April 2012, as far as I can determine.

January 2012 update: I added calling codes for as many countries as I was able to find. One, Heard Island and McDonald Islands, has no calling code as apparently there are no landline phones there. Data represented by a question mark is included in the table as "NULL" and indicates that I am unaware of whether that data exists, and if it does, what it is. 

-- Table structure for table `country_t`

  `country_id` int(5) NOT NULL AUTO_INCREMENT,
  `iso2` char(2) DEFAULT NULL,
  `short_name` varchar(80) NOT NULL DEFAULT '',
  `long_name` varchar(80) NOT NULL DEFAULT '',
  `iso3` char(3) DEFAULT NULL,
  `numcode` varchar(6) DEFAULT NULL,
  `un_member` varchar(12) DEFAULT NULL,
  `calling_code` varchar(8) DEFAULT NULL,
  `cctld` varchar(5) DEFAULT NULL,
  PRIMARY KEY (`country_id`)

-- Dumping data for table `country_t`

INSERT INTO `country_t` (`country_id`, `iso2`, `short_name`, `long_name`, `iso3`, `numcode`, `un_member`, `calling_code`, `cctld`) VALUES
(1, 'AF', 'Afghanistan', 'Islamic Republic of Afghanistan', 'AFG', '004', 'yes', '93', '.af'),
(2, 'AX', 'Aland Islands', '&Aring;land Islands', 'ALA', '248', 'no', '358', '.ax'),
(3, 'AL', 'Albania', 'Republic of Albania', 'ALB', '008', 'yes', '355', '.al'),
(4, 'DZ', 'Algeria', 'People''s Democratic Republic of Algeria', 'DZA', '012', 'yes', '213', '.dz'),
(5, 'AS', 'American Samoa', 'American Samoa', 'ASM', '016', 'no', '1+684', '.as'),
(6, 'AD', 'Andorra', 'Principality of Andorra', 'AND', '020', 'yes', '376', '.ad'),
(7, 'AO', 'Angola', 'Republic of Angola', 'AGO', '024', 'yes', '244', '.ao'),
(8, 'AI', 'Anguilla', 'Anguilla', 'AIA', '660', 'no', '1+264', '.ai'),
(9, 'AQ', 'Antarctica', 'Antarctica', 'ATA', '010', 'no', '672', '.aq'),
(10, 'AG', 'Antigua and Barbuda', 'Antigua and Barbuda', 'ATG', '028', 'yes', '1+268', '.ag'),
(11, 'AR', 'Argentina', 'Argentine Republic', 'ARG', '032', 'yes', '54', '.ar'),
(12, 'AM', 'Armenia', 'Republic of Armenia', 'ARM', '051', 'yes', '374', '.am'),
(13, 'AW', 'Aruba', 'Aruba', 'ABW', '533', 'no', '297', '.aw'),
(14, 'AU', 'Australia', 'Commonwealth of Australia', 'AUS', '036', 'yes', '61', '.au'),
(15, 'AT', 'Austria', 'Republic of Austria', 'AUT', '040', 'yes', '43', '.at'),
(16, 'AZ', 'Azerbaijan', 'Republic of Azerbaijan', 'AZE', '031', 'yes', '994', '.az'),
(17, 'BS', 'Bahamas', 'Commonwealth of The Bahamas', 'BHS', '044', 'yes', '1+242', '.bs'),
(18, 'BH', 'Bahrain', 'Kingdom of Bahrain', 'BHR', '048', 'yes', '973', '.bh'),
(19, 'BD', 'Bangladesh', 'People''s Republic of Bangladesh', 'BGD', '050', 'yes', '880', '.bd'),
(20, 'BB', 'Barbados', 'Barbados', 'BRB', '052', 'yes', '1+246', '.bb'),
(21, 'BY', 'Belarus', 'Republic of Belarus', 'BLR', '112', 'yes', '375', '.by'),
(22, 'BE', 'Belgium', 'Kingdom of Belgium', 'BEL', '056', 'yes', '32', '.be'),
(23, 'BZ', 'Belize', 'Belize', 'BLZ', '084', 'yes', '501', '.bz'),
(24, 'BJ', 'Benin', 'Republic of Benin', 'BEN', '204', 'yes', '229', '.bj'),
(25, 'BM', 'Bermuda', 'Bermuda Islands', 'BMU', '060', 'no', '1+441', '.bm'),
(26, 'BT', 'Bhutan', 'Kingdom of Bhutan', 'BTN', '064', 'yes', '975', '.bt'),
(27, 'BO', 'Bolivia', 'Plurinational State of Bolivia', 'BOL', '068', 'yes', '591', '.bo'),
(28, 'BQ', 'Bonaire, Sint Eustatius and Saba', 'Bonaire, Sint Eustatius and Saba', 'BES', '535', 'no', '599', '.bq'),
(29, 'BA', 'Bosnia and Herzegovina', 'Bosnia and Herzegovina', 'BIH', '070', 'yes', '387', '.ba'),
(30, 'BW', 'Botswana', 'Republic of Botswana', 'BWA', '072', 'yes', '267', '.bw'),
(31, 'BV', 'Bouvet Island', 'Bouvet Island', 'BVT', '074', 'no', 'NONE', '.bv'),
(32, 'BR', 'Brazil', 'Federative Republic of Brazil', 'BRA', '076', 'yes', '55', '.br'),
(33, 'IO', 'British Indian Ocean Territory', 'British Indian Ocean Territory', 'IOT', '086', 'no', '246', '.io'),
(34, 'BN', 'Brunei', 'Brunei Darussalam', 'BRN', '096', 'yes', '673', '.bn'),
(35, 'BG', 'Bulgaria', 'Republic of Bulgaria', 'BGR', '100', 'yes', '359', '.bg'),
(36, 'BF', 'Burkina Faso', 'Burkina Faso', 'BFA', '854', 'yes', '226', '.bf'),
(37, 'BI', 'Burundi', 'Republic of Burundi', 'BDI', '108', 'yes', '257', '.bi'),
(38, 'KH', 'Cambodia', 'Kingdom of Cambodia', 'KHM', '116', 'yes', '855', '.kh'),
(39, 'CM', 'Cameroon', 'Republic of Cameroon', 'CMR', '120', 'yes', '237', '.cm'),
(40, 'CA', 'Canada', 'Canada', 'CAN', '124', 'yes', '1', '.ca'),
(41, 'CV', 'Cape Verde', 'Republic of Cape Verde', 'CPV', '132', 'yes', '238', '.cv'),
(42, 'KY', 'Cayman Islands', 'The Cayman Islands', 'CYM', '136', 'no', '1+345', '.ky'),
(43, 'CF', 'Central African Republic', 'Central African Republic', 'CAF', '140', 'yes', '236', '.cf'),
(44, 'TD', 'Chad', 'Republic of Chad', 'TCD', '148', 'yes', '235', '.td'),
(45, 'CL', 'Chile', 'Republic of Chile', 'CHL', '152', 'yes', '56', '.cl'),
(46, 'CN', 'China', 'People''s Republic of China', 'CHN', '156', 'yes', '86', '.cn'),
(47, 'CX', 'Christmas Island', 'Christmas Island', 'CXR', '162', 'no', '61', '.cx'),
(48, 'CC', 'Cocos (Keeling) Islands', 'Cocos (Keeling) Islands', 'CCK', '166', 'no', '61', '.cc'),
(49, 'CO', 'Colombia', 'Republic of Colombia', 'COL', '170', 'yes', '57', '.co'),
(50, 'KM', 'Comoros', 'Union of the Comoros', 'COM', '174', 'yes', '269', '.km'),
(51, 'CG', 'Congo', 'Republic of the Congo', 'COG', '178', 'yes', '242', '.cg'),
(52, 'CK', 'Cook Islands', 'Cook Islands', 'COK', '184', 'some', '682', '.ck'),
(53, 'CR', 'Costa Rica', 'Republic of Costa Rica', 'CRI', '188', 'yes', '506', '.cr'),
(54, 'CI', 'Cote d''ivoire (Ivory Coast)', 'Republic of C&ocirc;te D''Ivoire (Ivory Coast)', 'CIV', '384', 'yes', '225', '.ci'),
(55, 'HR', 'Croatia', 'Republic of Croatia', 'HRV', '191', 'yes', '385', '.hr'),
(56, 'CU', 'Cuba', 'Republic of Cuba', 'CUB', '192', 'yes', '53', '.cu'),
(57, 'CW', 'Curacao', 'Cura&ccedil;ao', 'CUW', '531', 'no', '599', '.cw'),
(58, 'CY', 'Cyprus', 'Republic of Cyprus', 'CYP', '196', 'yes', '357', '.cy'),
(59, 'CZ', 'Czech Republic', 'Czech Republic', 'CZE', '203', 'yes', '420', '.cz'),
(60, 'CD', 'Democratic Republic of the Congo', 'Democratic Republic of the Congo', 'COD', '180', 'yes', '243', '.cd'),
(61, 'DK', 'Denmark', 'Kingdom of Denmark', 'DNK', '208', 'yes', '45', '.dk'),
(62, 'DJ', 'Djibouti', 'Republic of Djibouti', 'DJI', '262', 'yes', '253', '.dj'),
(63, 'DM', 'Dominica', 'Commonwealth of Dominica', 'DMA', '212', 'yes', '1+767', '.dm'),
(64, 'DO', 'Dominican Republic', 'Dominican Republic', 'DOM', '214', 'yes', '1+809, 8', '.do'),
(65, 'EC', 'Ecuador', 'Republic of Ecuador', 'ECU', '218', 'yes', '593', '.ec'),
(66, 'EG', 'Egypt', 'Arab Republic of Egypt', 'EGY', '818', 'yes', '20', '.eg'),
(67, 'SV', 'El Salvador', 'Republic of El Salvador', 'SLV', '222', 'yes', '503', '.sv'),
(68, 'GQ', 'Equatorial Guinea', 'Republic of Equatorial Guinea', 'GNQ', '226', 'yes', '240', '.gq'),
(69, 'ER', 'Eritrea', 'State of Eritrea', 'ERI', '232', 'yes', '291', '.er'),
(70, 'EE', 'Estonia', 'Republic of Estonia', 'EST', '233', 'yes', '372', '.ee'),
(71, 'ET', 'Ethiopia', 'Federal Democratic Republic of Ethiopia', 'ETH', '231', 'yes', '251', '.et'),
(72, 'FK', 'Falkland Islands (Malvinas)', 'The Falkland Islands (Malvinas)', 'FLK', '238', 'no', '500', '.fk'),
(73, 'FO', 'Faroe Islands', 'The Faroe Islands', 'FRO', '234', 'no', '298', '.fo'),
(74, 'FJ', 'Fiji', 'Republic of Fiji', 'FJI', '242', 'yes', '679', '.fj'),
(75, 'FI', 'Finland', 'Republic of Finland', 'FIN', '246', 'yes', '358', '.fi'),
(76, 'FR', 'France', 'French Republic', 'FRA', '250', 'yes', '33', '.fr'),
(77, 'GF', 'French Guiana', 'French Guiana', 'GUF', '254', 'no', '594', '.gf'),
(78, 'PF', 'French Polynesia', 'French Polynesia', 'PYF', '258', 'no', '689', '.pf'),
(79, 'TF', 'French Southern Territories', 'French Southern Territories', 'ATF', '260', 'no', NULL, '.tf'),
(80, 'GA', 'Gabon', 'Gabonese Republic', 'GAB', '266', 'yes', '241', '.ga'),
(81, 'GM', 'Gambia', 'Republic of The Gambia', 'GMB', '270', 'yes', '220', '.gm'),
(82, 'GE', 'Georgia', 'Georgia', 'GEO', '268', 'yes', '995', '.ge'),
(83, 'DE', 'Germany', 'Federal Republic of Germany', 'DEU', '276', 'yes', '49', '.de'),
(84, 'GH', 'Ghana', 'Republic of Ghana', 'GHA', '288', 'yes', '233', '.gh'),
(85, 'GI', 'Gibraltar', 'Gibraltar', 'GIB', '292', 'no', '350', '.gi'),
(86, 'GR', 'Greece', 'Hellenic Republic', 'GRC', '300', 'yes', '30', '.gr'),
(87, 'GL', 'Greenland', 'Greenland', 'GRL', '304', 'no', '299', '.gl'),
(88, 'GD', 'Grenada', 'Grenada', 'GRD', '308', 'yes', '1+473', '.gd'),
(89, 'GP', 'Guadaloupe', 'Guadeloupe', 'GLP', '312', 'no', '590', '.gp'),
(90, 'GU', 'Guam', 'Guam', 'GUM', '316', 'no', '1+671', '.gu'),
(91, 'GT', 'Guatemala', 'Republic of Guatemala', 'GTM', '320', 'yes', '502', '.gt'),
(92, 'GG', 'Guernsey', 'Guernsey', 'GGY', '831', 'no', '44', '.gg'),
(93, 'GN', 'Guinea', 'Republic of Guinea', 'GIN', '324', 'yes', '224', '.gn'),
(94, 'GW', 'Guinea-Bissau', 'Republic of Guinea-Bissau', 'GNB', '624', 'yes', '245', '.gw'),
(95, 'GY', 'Guyana', 'Co-operative Republic of Guyana', 'GUY', '328', 'yes', '592', '.gy'),
(96, 'HT', 'Haiti', 'Republic of Haiti', 'HTI', '332', 'yes', '509', '.ht'),
(97, 'HM', 'Heard Island and McDonald Islands', 'Heard Island and McDonald Islands', 'HMD', '334', 'no', 'NONE', '.hm'),
(98, 'HN', 'Honduras', 'Republic of Honduras', 'HND', '340', 'yes', '504', '.hn'),
(99, 'HK', 'Hong Kong', 'Hong Kong', 'HKG', '344', 'no', '852', '.hk'),
(100, 'HU', 'Hungary', 'Hungary', 'HUN', '348', 'yes', '36', '.hu'),
(101, 'IS', 'Iceland', 'Republic of Iceland', 'ISL', '352', 'yes', '354', '.is'),
(102, 'IN', 'India', 'Republic of India', 'IND', '356', 'yes', '91', '.in'),
(103, 'ID', 'Indonesia', 'Republic of Indonesia', 'IDN', '360', 'yes', '62', '.id'),
(104, 'IR', 'Iran', 'Islamic Republic of Iran', 'IRN', '364', 'yes', '98', '.ir'),
(105, 'IQ', 'Iraq', 'Republic of Iraq', 'IRQ', '368', 'yes', '964', '.iq'),
(106, 'IE', 'Ireland', 'Ireland', 'IRL', '372', 'yes', '353', '.ie'),
(107, 'IM', 'Isle of Man', 'Isle of Man', 'IMN', '833', 'no', '44', '.im'),
(108, 'IL', 'Israel', 'State of Israel', 'ISR', '376', 'yes', '972', '.il'),
(109, 'IT', 'Italy', 'Italian Republic', 'ITA', '380', 'yes', '39', '.jm'),
(110, 'JM', 'Jamaica', 'Jamaica', 'JAM', '388', 'yes', '1+876', '.jm'),
(111, 'JP', 'Japan', 'Japan', 'JPN', '392', 'yes', '81', '.jp'),
(112, 'JE', 'Jersey', 'The Bailiwick of Jersey', 'JEY', '832', 'no', '44', '.je'),
(113, 'JO', 'Jordan', 'Hashemite Kingdom of Jordan', 'JOR', '400', 'yes', '962', '.jo'),
(114, 'KZ', 'Kazakhstan', 'Republic of Kazakhstan', 'KAZ', '398', 'yes', '7', '.kz'),
(115, 'KE', 'Kenya', 'Republic of Kenya', 'KEN', '404', 'yes', '254', '.ke'),
(116, 'KI', 'Kiribati', 'Republic of Kiribati', 'KIR', '296', 'yes', '686', '.ki'),
(117, 'XK', 'Kosovo', 'Republic of Kosovo', '---', '---', 'some', '381', ''),
(118, 'KW', 'Kuwait', 'State of Kuwait', 'KWT', '414', 'yes', '965', '.kw'),
(119, 'KG', 'Kyrgyzstan', 'Kyrgyz Republic', 'KGZ', '417', 'yes', '996', '.kg'),
(120, 'LA', 'Laos', 'Lao People''s Democratic Republic', 'LAO', '418', 'yes', '856', '.la'),
(121, 'LV', 'Latvia', 'Republic of Latvia', 'LVA', '428', 'yes', '371', '.lv'),
(122, 'LB', 'Lebanon', 'Republic of Lebanon', 'LBN', '422', 'yes', '961', '.lb'),
(123, 'LS', 'Lesotho', 'Kingdom of Lesotho', 'LSO', '426', 'yes', '266', '.ls'),
(124, 'LR', 'Liberia', 'Republic of Liberia', 'LBR', '430', 'yes', '231', '.lr'),
(125, 'LY', 'Libya', 'Libya', 'LBY', '434', 'yes', '218', '.ly'),
(126, 'LI', 'Liechtenstein', 'Principality of Liechtenstein', 'LIE', '438', 'yes', '423', '.li'),
(127, 'LT', 'Lithuania', 'Republic of Lithuania', 'LTU', '440', 'yes', '370', '.lt'),
(128, 'LU', 'Luxembourg', 'Grand Duchy of Luxembourg', 'LUX', '442', 'yes', '352', '.lu'),
(129, 'MO', 'Macao', 'The Macao Special Administrative Region', 'MAC', '446', 'no', '853', '.mo'),
(130, 'MK', 'Macedonia', 'The Former Yugoslav Republic of Macedonia', 'MKD', '807', 'yes', '389', '.mk'),
(131, 'MG', 'Madagascar', 'Republic of Madagascar', 'MDG', '450', 'yes', '261', '.mg'),
(132, 'MW', 'Malawi', 'Republic of Malawi', 'MWI', '454', 'yes', '265', '.mw'),
(133, 'MY', 'Malaysia', 'Malaysia', 'MYS', '458', 'yes', '60', '.my'),
(134, 'MV', 'Maldives', 'Republic of Maldives', 'MDV', '462', 'yes', '960', '.mv'),
(135, 'ML', 'Mali', 'Republic of Mali', 'MLI', '466', 'yes', '223', '.ml'),
(136, 'MT', 'Malta', 'Republic of Malta', 'MLT', '470', 'yes', '356', '.mt'),
(137, 'MH', 'Marshall Islands', 'Republic of the Marshall Islands', 'MHL', '584', 'yes', '692', '.mh'),
(138, 'MQ', 'Martinique', 'Martinique', 'MTQ', '474', 'no', '596', '.mq'),
(139, 'MR', 'Mauritania', 'Islamic Republic of Mauritania', 'MRT', '478', 'yes', '222', '.mr'),
(140, 'MU', 'Mauritius', 'Republic of Mauritius', 'MUS', '480', 'yes', '230', '.mu'),
(141, 'YT', 'Mayotte', 'Mayotte', 'MYT', '175', 'no', '262', '.yt'),
(142, 'MX', 'Mexico', 'United Mexican States', 'MEX', '484', 'yes', '52', '.mx'),
(143, 'FM', 'Micronesia', 'Federated States of Micronesia', 'FSM', '583', 'yes', '691', '.fm'),
(144, 'MD', 'Moldava', 'Republic of Moldova', 'MDA', '498', 'yes', '373', '.md'),
(145, 'MC', 'Monaco', 'Principality of Monaco', 'MCO', '492', 'yes', '377', '.mc'),
(146, 'MN', 'Mongolia', 'Mongolia', 'MNG', '496', 'yes', '976', '.mn'),
(147, 'ME', 'Montenegro', 'Montenegro', 'MNE', '499', 'yes', '382', '.me'),
(148, 'MS', 'Montserrat', 'Montserrat', 'MSR', '500', 'no', '1+664', '.ms'),
(149, 'MA', 'Morocco', 'Kingdom of Morocco', 'MAR', '504', 'yes', '212', '.ma'),
(150, 'MZ', 'Mozambique', 'Republic of Mozambique', 'MOZ', '508', 'yes', '258', '.mz'),
(151, 'MM', 'Myanmar (Burma)', 'Republic of the Union of Myanmar', 'MMR', '104', 'yes', '95', '.mm'),
(152, 'NA', 'Namibia', 'Republic of Namibia', 'NAM', '516', 'yes', '264', '.na'),
(153, 'NR', 'Nauru', 'Republic of Nauru', 'NRU', '520', 'yes', '674', '.nr'),
(154, 'NP', 'Nepal', 'Federal Democratic Republic of Nepal', 'NPL', '524', 'yes', '977', '.np'),
(155, 'NL', 'Netherlands', 'Kingdom of the Netherlands', 'NLD', '528', 'yes', '31', '.nl'),
(156, 'NC', 'New Caledonia', 'New Caledonia', 'NCL', '540', 'no', '687', '.nc'),
(157, 'NZ', 'New Zealand', 'New Zealand', 'NZL', '554', 'yes', '64', '.nz'),
(158, 'NI', 'Nicaragua', 'Republic of Nicaragua', 'NIC', '558', 'yes', '505', '.ni'),
(159, 'NE', 'Niger', 'Republic of Niger', 'NER', '562', 'yes', '227', '.ne'),
(160, 'NG', 'Nigeria', 'Federal Republic of Nigeria', 'NGA', '566', 'yes', '234', '.ng'),
(161, 'NU', 'Niue', 'Niue', 'NIU', '570', 'some', '683', '.nu'),
(162, 'NF', 'Norfolk Island', 'Norfolk Island', 'NFK', '574', 'no', '672', '.nf'),
(163, 'KP', 'North Korea', 'Democratic People''s Republic of Korea', 'PRK', '408', 'yes', '850', '.kp'),
(164, 'MP', 'Northern Mariana Islands', 'Northern Mariana Islands', 'MNP', '580', 'no', '1+670', '.mp'),
(165, 'NO', 'Norway', 'Kingdom of Norway', 'NOR', '578', 'yes', '47', '.no'),
(166, 'OM', 'Oman', 'Sultanate of Oman', 'OMN', '512', 'yes', '968', '.om'),
(167, 'PK', 'Pakistan', 'Islamic Republic of Pakistan', 'PAK', '586', 'yes', '92', '.pk'),
(168, 'PW', 'Palau', 'Republic of Palau', 'PLW', '585', 'yes', '680', '.pw'),
(169, 'PS', 'Palestine', 'State of Palestine (or Occupied Palestinian Territory)', 'PSE', '275', 'some', '970', '.ps'),
(170, 'PA', 'Panama', 'Republic of Panama', 'PAN', '591', 'yes', '507', '.pa'),
(171, 'PG', 'Papua New Guinea', 'Independent State of Papua New Guinea', 'PNG', '598', 'yes', '675', '.pg'),
(172, 'PY', 'Paraguay', 'Republic of Paraguay', 'PRY', '600', 'yes', '595', '.py'),
(173, 'PE', 'Peru', 'Republic of Peru', 'PER', '604', 'yes', '51', '.pe'),
(174, 'PH', 'Phillipines', 'Republic of the Philippines', 'PHL', '608', 'yes', '63', '.ph'),
(175, 'PN', 'Pitcairn', 'Pitcairn', 'PCN', '612', 'no', 'NONE', '.pn'),
(176, 'PL', 'Poland', 'Republic of Poland', 'POL', '616', 'yes', '48', '.pl'),
(177, 'PT', 'Portugal', 'Portuguese Republic', 'PRT', '620', 'yes', '351', '.pt'),
(178, 'PR', 'Puerto Rico', 'Commonwealth of Puerto Rico', 'PRI', '630', 'no', '1+939', '.pr'),
(179, 'QA', 'Qatar', 'State of Qatar', 'QAT', '634', 'yes', '974', '.qa'),
(180, 'RE', 'Reunion', 'R&eacute;union', 'REU', '638', 'no', '262', '.re'),
(181, 'RO', 'Romania', 'Romania', 'ROU', '642', 'yes', '40', '.ro'),
(182, 'RU', 'Russia', 'Russian Federation', 'RUS', '643', 'yes', '7', '.ru'),
(183, 'RW', 'Rwanda', 'Republic of Rwanda', 'RWA', '646', 'yes', '250', '.rw'),
(184, 'BL', 'Saint Barthelemy', 'Saint Barth&eacute;lemy', 'BLM', '652', 'no', '590', '.bl'),
(185, 'SH', 'Saint Helena', 'Saint Helena, Ascension and Tristan da Cunha', 'SHN', '654', 'no', '290', '.sh'),
(186, 'KN', 'Saint Kitts and Nevis', 'Federation of Saint Christopher and Nevis', 'KNA', '659', 'yes', '1+869', '.kn'),
(187, 'LC', 'Saint Lucia', 'Saint Lucia', 'LCA', '662', 'yes', '1+758', '.lc'),
(188, 'MF', 'Saint Martin', 'Saint Martin', 'MAF', '663', 'no', '590', '.mf'),
(189, 'PM', 'Saint Pierre and Miquelon', 'Saint Pierre and Miquelon', 'SPM', '666', 'no', '508', '.pm'),
(190, 'VC', 'Saint Vincent and the Grenadines', 'Saint Vincent and the Grenadines', 'VCT', '670', 'yes', '1+784', '.vc'),
(191, 'WS', 'Samoa', 'Independent State of Samoa', 'WSM', '882', 'yes', '685', '.ws'),
(192, 'SM', 'San Marino', 'Republic of San Marino', 'SMR', '674', 'yes', '378', '.sm'),
(193, 'ST', 'Sao Tome and Principe', 'Democratic Republic of S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'STP', '678', 'yes', '239', '.st'),
(194, 'SA', 'Saudi Arabia', 'Kingdom of Saudi Arabia', 'SAU', '682', 'yes', '966', '.sa'),
(195, 'SN', 'Senegal', 'Republic of Senegal', 'SEN', '686', 'yes', '221', '.sn'),
(196, 'RS', 'Serbia', 'Republic of Serbia', 'SRB', '688', 'yes', '381', '.rs'),
(197, 'SC', 'Seychelles', 'Republic of Seychelles', 'SYC', '690', 'yes', '248', '.sc'),
(198, 'SL', 'Sierra Leone', 'Republic of Sierra Leone', 'SLE', '694', 'yes', '232', '.sl'),
(199, 'SG', 'Singapore', 'Republic of Singapore', 'SGP', '702', 'yes', '65', '.sg'),
(200, 'SX', 'Sint Maarten', 'Sint Maarten', 'SXM', '534', 'no', '1+721', '.sx'),
(201, 'SK', 'Slovakia', 'Slovak Republic', 'SVK', '703', 'yes', '421', '.sk'),
(202, 'SI', 'Slovenia', 'Republic of Slovenia', 'SVN', '705', 'yes', '386', '.si'),
(203, 'SB', 'Solomon Islands', 'Solomon Islands', 'SLB', '090', 'yes', '677', '.sb'),
(204, 'SO', 'Somalia', 'Somali Republic', 'SOM', '706', 'yes', '252', '.so'),
(205, 'ZA', 'South Africa', 'Republic of South Africa', 'ZAF', '710', 'yes', '27', '.za'),
(206, 'GS', 'South Georgia and the South Sandwich Islands', 'South Georgia and the South Sandwich Islands', 'SGS', '239', 'no', '500', '.gs'),
(207, 'KR', 'South Korea', 'Republic of Korea', 'KOR', '410', 'yes', '82', '.kr'),
(208, 'SS', 'South Sudan', 'Republic of South Sudan', 'SSD', '728', 'yes', '211', '.ss'),
(209, 'ES', 'Spain', 'Kingdom of Spain', 'ESP', '724', 'yes', '34', '.es'),
(210, 'LK', 'Sri Lanka', 'Democratic Socialist Republic of Sri Lanka', 'LKA', '144', 'yes', '94', '.lk'),
(211, 'SD', 'Sudan', 'Republic of the Sudan', 'SDN', '729', 'yes', '249', '.sd'),
(212, 'SR', 'Suriname', 'Republic of Suriname', 'SUR', '740', 'yes', '597', '.sr'),
(213, 'SJ', 'Svalbard and Jan Mayen', 'Svalbard and Jan Mayen', 'SJM', '744', 'no', '47', '.sj'),
(214, 'SZ', 'Swaziland', 'Kingdom of Swaziland', 'SWZ', '748', 'yes', '268', '.sz'),
(215, 'SE', 'Sweden', 'Kingdom of Sweden', 'SWE', '752', 'yes', '46', '.se'),
(216, 'CH', 'Switzerland', 'Swiss Confederation', 'CHE', '756', 'yes', '41', '.ch'),
(217, 'SY', 'Syria', 'Syrian Arab Republic', 'SYR', '760', 'yes', '963', '.sy'),
(218, 'TW', 'Taiwan', 'Republic of China (Taiwan)', 'TWN', '158', 'former', '886', '.tw'),
(219, 'TJ', 'Tajikistan', 'Republic of Tajikistan', 'TJK', '762', 'yes', '992', '.tj'),
(220, 'TZ', 'Tanzania', 'United Republic of Tanzania', 'TZA', '834', 'yes', '255', '.tz'),
(221, 'TH', 'Thailand', 'Kingdom of Thailand', 'THA', '764', 'yes', '66', '.th'),
(222, 'TL', 'Timor-Leste (East Timor)', 'Democratic Republic of Timor-Leste', 'TLS', '626', 'yes', '670', '.tl'),
(223, 'TG', 'Togo', 'Togolese Republic', 'TGO', '768', 'yes', '228', '.tg'),
(224, 'TK', 'Tokelau', 'Tokelau', 'TKL', '772', 'no', '690', '.tk'),
(225, 'TO', 'Tonga', 'Kingdom of Tonga', 'TON', '776', 'yes', '676', '.to'),
(226, 'TT', 'Trinidad and Tobago', 'Republic of Trinidad and Tobago', 'TTO', '780', 'yes', '1+868', '.tt'),
(227, 'TN', 'Tunisia', 'Republic of Tunisia', 'TUN', '788', 'yes', '216', '.tn'),
(228, 'TR', 'Turkey', 'Republic of Turkey', 'TUR', '792', 'yes', '90', '.tr'),
(229, 'TM', 'Turkmenistan', 'Turkmenistan', 'TKM', '795', 'yes', '993', '.tm'),
(230, 'TC', 'Turks and Caicos Islands', 'Turks and Caicos Islands', 'TCA', '796', 'no', '1+649', '.tc'),
(231, 'TV', 'Tuvalu', 'Tuvalu', 'TUV', '798', 'yes', '688', '.tv'),
(232, 'UG', 'Uganda', 'Republic of Uganda', 'UGA', '800', 'yes', '256', '.ug'),
(233, 'UA', 'Ukraine', 'Ukraine', 'UKR', '804', 'yes', '380', '.ua'),
(234, 'AE', 'United Arab Emirates', 'United Arab Emirates', 'ARE', '784', 'yes', '971', '.ae'),
(235, 'GB', 'United Kingdom', 'United Kingdom of Great Britain and Nothern Ireland', 'GBR', '826', 'yes', '44', '.uk'),
(236, 'US', 'United States', 'United States of America', 'USA', '840', 'yes', '1', '.us'),
(237, 'UM', 'United States Minor Outlying Islands', 'United States Minor Outlying Islands', 'UMI', '581', 'no', 'NONE', 'NONE'),
(238, 'UY', 'Uruguay', 'Eastern Republic of Uruguay', 'URY', '858', 'yes', '598', '.uy'),
(239, 'UZ', 'Uzbekistan', 'Republic of Uzbekistan', 'UZB', '860', 'yes', '998', '.uz'),
(240, 'VU', 'Vanuatu', 'Republic of Vanuatu', 'VUT', '548', 'yes', '678', '.vu'),
(241, 'VA', 'Vatican City', 'State of the Vatican City', 'VAT', '336', 'no', '39', '.va'),
(242, 'VE', 'Venezuela', 'Bolivarian Republic of Venezuela', 'VEN', '862', 'yes', '58', '.ve'),
(243, 'VN', 'Vietnam', 'Socialist Republic of Vietnam', 'VNM', '704', 'yes', '84', '.vn'),
(244, 'VG', 'Virgin Islands, British', 'British Virgin Islands', 'VGB', '092', 'no', '1+284', '.vg'),
(245, 'VI', 'Virgin Islands, US', 'Virgin Islands of the United States', 'VIR', '850', 'no', '1+340', '.vi'),
(246, 'WF', 'Wallis and Futuna', 'Wallis and Futuna', 'WLF', '876', 'no', '681', '.wf'),
(247, 'EH', 'Western Sahara', 'Western Sahara', 'ESH', '732', 'no', '212', '.eh'),
(248, 'YE', 'Yemen', 'Republic of Yemen', 'YEM', '887', 'yes', '967', '.ye'),
(249, 'ZM', 'Zambia', 'Republic of Zambia', 'ZMB', '894', 'yes', '260', '.zm'),
(250, 'ZW', 'Zimbabwe', 'Republic of Zimbabwe', 'ZWE', '716', 'yes', '263', '.zw');

MySQL List of States & PHP Function for Select Box

After the first few 5:00am "ohmigod I need a list of states NOW!" moments that I had when I started coding, I figured I'd dump a generic table and use that for future reference. This is the basic table--it can be modified as needed. It includes Washington DC and the three Armed Forces abbreviations: AA, AE, and AP.

Copy and paste the contents of this box either into your SQL command window if you're using the command line or into the big textbox on the "SQL" tab in phpMyAdmin. 

  `state_id` int(3) NOT NULL auto_increment COMMENT 'PK: Unique Identifier',
  `state_name` varchar(50) NOT NULL default '' COMMENT 'State Name',
  `state_abbr` varchar(10) default NULL COMMENT 'State Abbreviation',
  PRIMARY KEY  (`state_id`)

-- Dumping data for table `state_t`

INSERT INTO `state_t` (`state_id`, `state_name`, `state_abbr`) VALUES
(1, 'Alabama', 'AL'),
(2, 'Alaska', 'AK'),
(3, 'Arizona', 'AZ'),
(4, 'Arkansas', 'AR'),
(5, 'California', 'CA'),
(6, 'Colorado', 'CO'),
(7, 'Connecticut', 'CT'),
(8, 'Delaware', 'DE'),
(9, 'District of Columbia', 'DC'),
(10, 'Florida', 'FL'),
(11, 'Georgia', 'GA'),
(12, 'Hawaii', 'HI'),
(13, 'Idaho', 'ID'),
(14, 'Illinois', 'IL'),
(15, 'Indiana', 'IN'),
(16, 'Iowa', 'IA'),
(17, 'Kansas', 'KS'),
(18, 'Kentucky', 'KY'),
(19, 'Louisiana', 'LA'),
(20, 'Maine', 'ME'),
(21, 'Maryland', 'MD'),
(22, 'Massachusetts', 'MA'),
(23, 'Michigan', 'MI'),
(24, 'Minnesota', 'MN'),
(25, 'Mississippi', 'MS'),
(26, 'Missouri', 'MO'),
(27, 'Montana', 'MT'),
(28, 'Nebraska', 'NE'),
(29, 'Nevada', 'NV'),
(30, 'New Hampshire', 'NH'),
(31, 'New Jersey', 'NJ'),
(32, 'New Mexico', 'NM'),
(33, 'New York', 'NY'),
(34, 'North Carolina', 'NC'),
(35, 'North Dakota', 'ND'),
(36, 'Ohio', 'OH'),
(37, 'Oklahoma', 'OK'),
(38, 'Oregon', 'OR'),
(39, 'Pennsylvania', 'PA'),
(40, 'Rhode Island', 'RI'),
(41, 'South Carolina', 'SC'),
(42, 'South Dakota', 'SD'),
(43, 'Tennessee', 'TN'),
(44, 'Texas', 'TX'),
(45, 'Utah', 'UT'),
(46, 'Vermont', 'VT'),
(47, 'Virginia', 'VA'),
(48, 'Washington', 'WA'),
(49, 'West Virginia', 'WV'),
(50, 'Wisconsin', 'WI'),
(51, 'Wyoming', 'WY'),
(52, 'Armed Forces - Americas', 'AA'),
(53, 'Armed Forces - Europe', 'AE'),
(54, 'Armed Forces - Pacific', 'AP');

Create variables and an array as below. Personally, I place this variable in a file called "settings.php" which I include at the top of every file that references the database in any way.

$dbname = "mydatabase_name";        // Database name
$dbuser = "my_username";            // Database username
$dbpass = "password";               // Database password
$dbhost = "localhost";              // Database host

$dbvariables = Array (              // Array to hold db variables
  "dbhost" => $dbhost,
  "dbuser" => $dbuser,
  "dbpass" => $dbpass,
  "dbname" => $dbname

Place the following function in an appropriate location, I place it in an external file (like the settings.php file) and include it at the top of every file.

function state_select($dbvariables) {
<select name="state">
<option value="">--</option>
   dbConnect($dbvariables);                   // Connect to MySQL
   mysql_select_db($dbvariables['dbname']);   // Select database

   $query = 'SELECT * from `state_t` WHERE 1 ORDER BY `state_name` ASC';
   $result = mysql_query($query) or die(mysql_error());

   while ($x = mysql_fetch_array($result, MYSQL_ASSOC)) {

      $state_id   = $x['state_id'];
      $state_name = $x['state_name'];
<option value="<?php echo $state_id; ?>"><?php echo $state_name; ?></option>

Search Help: Visitors seeking this information might use the following search strings: List of states in MySQL database format, MySQL List of States, MySQL state list, php MySQL list of states, php list state function.

How to Strip Non-Alphanumeric Characters From a String with PHP?

There are often times when non-alphanumeric characters in a string can be troublesome. For example, if you are using a string in order to name a file, you would want to eliminate any characters that are illegal in a filename. The following two commands (you can nest them, if you want) will first strip out all the characters except spaces, then convert the spaces to hyphens (or you can use underscores, etc.). Use only the first, if you wish to keep the spaces.

$my_new_string = preg_replace("/[^a-zA-Z0-9\s]/", "", $original_string);

$my_new_string = str_replace(" ","-",$my_new_string);

How to Make Caps to the first letter automatically in PHP?

I want to make the first letter in a text box to be capital but i have no idea on how i can apply it. e.g sitholimela ----> Sitholimela

I want to apply this to a text box.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
  <title>Capitalizing first letter in a textbox</title>
  <script type="text/javascript">
  function capitalize(textboxid, str) {
      // string with alteast one character
      if (str && str.length >= 1)
          var firstChar = str.charAt(0);
          var remainingStr = str.slice(1);
          str = firstChar.toUpperCase() + remainingStr;
      document.getElementById(textboxid).value = str;
  <form name="myform" method="post">
      <input type="text" id="mytextbox" onkeyup="javascript:capitalize(, this.value);">

CSS Code

input[type=text] {
    text-transform: capitalize;

Another Simple Way:-

.cityname{text-transform: capitalize;}

Call this class in input type where you want to Caps your First Letter.

<input type=''text" class="cityname"

How to Get the Last Auto-Incremented Number From MySQL?

When you need to insert data into more than one table at a time in a normalized database with relationships between the tables, you will often need to obtain the record number of the data inserted into the first table before creating your query to insert data into the second table. This can be accomplished with a short series of commands. Use the following code immediately after you make the first query:

/* This query figures out what the last auto-
   incremented number was so that it can be 
   used in the next query or other action.
   This assumes you are using the $link variable
   used in most MySQL examples to store the
   information necessary to connect to your
   database.  */

$result = mysql_query($query, $link);
$row = mysql_fetch_array($result);
// following is the newly created record
$last_id = 0 + $row[0];

How to Get Image Size with PHP?

I include this here because I had to look it up a couple times at first, so I thought it might be useful to others. Often there is a need or desire to display an image which might not always have a consistent size. For example, if you are displaying an image gallery and don't want to take the time to resize all of your images but still want to have code that validates, you need to come up with some way to display the correct size of the image in the <img> tag. PHP provides a nifty function, getimagesize() for this purpose, but the function was written before CSS became the standard, so while it provides HTML-valid code, it does not provide nicely packaged XHTML-valid code.

So, you have two options:
  1. Use the HTML code, life won't end! You can do this by doing the following:
    $myimage = "";
    $size = getimagesize($myimage);
    then use the following in your HTML:
    <img src="/full/path/to/image.jpg" <?php echo $size[3]; ?> />
    which produces:
    <img src="/full/path/to/image.jpg" width="300" height="60" />
    where the width and height match those of your image.
  2. Use this nifty little function instead:
    function imageSize($size) {
     $width = $size[0];
     $height = $size[1];
     print 'style="width:' . $width . 'px;height:' . $height . 'px;"';
    $myimage = "";
    $size = getimagesize($myimage);
    <img src="/full/path/to/image.jpg" <?php imageSize($myimage); ?> />
    which produces:
    <img src="/full/path/to/image.jpg" style="width:300px;height:60px;" />
Don't forget to add the required alt tags!

How To Capitalize First Letter or Each Word of a string Using PHP?

ucwords — Uppercase the first character of each word in a string

string ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] )

Returns a string with the first character of each word in str capitalized, if that character is alphabetic.

strtoupper — Make a string uppercase

string strtoupper ( string $string )

Returns string with all alphabetic characters converted to uppercase.

ucfirst — Make a string's first character uppercase

string ucfirst ( string $str )

Returns a string with the first character of str capitalized, if that character is alphabetic.

strtolower — Make a string lowercase

string strtolower ( string $string )

Returns string with all alphabetic characters converted to lowercase.

Related functions:

strtolower() - converts a string to lowercase
lcfirst() - converts the first character of a string to lowercase
ucfirst() - converts the first character of a string to uppercase
ucwords() - converts the first character of each word in a string to uppercase

How to Display MySQL Dates in Other Formats using PHP?

MySQL stores dates in the format YYYY-MM-DD... which is great, it's consistent and easy to understand—If you happen to be a computer. Unfortunately, this format is rather confusing for humans, especially for humans which may be trying to communicate with individuals who read dates differently. For example, those of us in the US usually record the 10th of May in the year 2015 as 05/10/2015 whereas individuals in other countries often record the same date as 10/05/2015, causing considerable confusion in communication.

So what do we do to solve this? When in doubt, write it out! Here's how to take a date retrieved from a MySQL database by PHP and convert it to an international human-friendly format.

We'll first assume that you have retrieved your data into array $myrow. Say the date stored in MySQL is 2015-07-11. Here's how to display it in various forms. Precede each of these by echo or print, whichever is appropriate for your application. All of these can be modified as needed by using the various formatting characters as described in the PHP: date manual.

Desired TextCode
July 11, 2015date("F d, Y",strtotime($myrow['date']));
Saturday, July 11, 2015date("l, F d, Y",strtotime($myrow['date']));
Jul 11, 2015date("M d, Y",strtotime($myrow['date']));
11 July 2015date("d F Y",strtotime($myrow['date']));
11 Jul 2015date("d M Y",strtotime($myrow['date']));
Sat, 11 Jul 2015date("D, d M Y",strtotime($myrow['date']));
Saturday, the 11th of July, 2015date("l",strtotime($myrow['date'])) . ", the " . date("jS",strtotime($myrow['date'])) . " of " . date("F, Y",strtotime($myrow['date']));

Search Help: Visitors seeking this information might use the following search strings: "How do I display MySQL dates in other formats?", "MySQL dates PHP", "MySQL datestamp field", "MySQL datestamp format", "MySQL PHP date format", ""MySQL PHP date conversion", "Convert MySQL date in PHP".

Thursday, August 13, 2015

How to delete extra row in table in PHP?


function get_dest_info_night_city_opt($pid,$option)
$sql = $this->dbObj->query("SELECT * FROM addopt_dest_info where package_id='".$pid."' and optionname = '".$option."'");
$rowdest = $sql->fetchAll();
$indexlast =  count($rowdest);
foreach($rowdest as $tdest)
$tnight+= $tdest['num_night'];
if(++$i == $indexlast)
 $tcity.= $tdest['city_name'];
$tcity.= $tdest['city_name'].', ';
return $tcity.'<=>'.$tnight;

Tuesday, August 11, 2015

Top Search Engine Optimization Factors in 2015

Every two years, Moz surveys the opinions of dozens of the world's brightest search marketers and runs correlation studies to better understand the workings of search engine algorithms. We gather this data to gain insight into the factors that may help—or hurt—a website's visibility in search engines.

This year, Moz surveyed over 150 leading search marketers who provided expert opinions on over 90 ranking factors.

In addition, the Data Science team at Moz, lead by Dr. Matthew Peters, ran an extensive correlation study to determine which features of websites and webpages are associated with higher search rankings. For the first time this year, Moz partnered with several data partners to enhance the study, including SimilarWeb, DomainTools, and Ahrefs.

Note that these factors are not "proof" of what search engines use to rank websites, but simply show the characteristics of web pages that tend to rank higher. Combining this understanding with both experience and knowledge of search engine algorithms can help lead to better SEO practices.

What are Search Engine Ranking Factors in 2015?

We're excited to announce the results of Moz's biannual Search Engine Ranking Correlation Study and Expert Survey, a.k.a. Ranking Factors.

Moz's Ranking Factors study helps identify which attributes of pages and sites have the strongest association with ranking highly in Google. The study consists of two parts: a survey of professional SEOs and a large correlation study.

Announcing the 2015 Search Engine Ranking Factors Study

This year, with the help of Moz's data scientist Dr. Matt Peters, new data partners, and over 150 search marketing professionals, we were able to study more data points than in any year past. All together, we measured over 170 correlations and collected over 15,000 data points from our panel of SEO experts.

Ready to dig in?

We want to especially thank our data partners. SimilarWeb, Ahrefs, and DomainTools each gave us unparallelled access and their data was essential to helping make this study a success. It's amazing and wonderful when different companies—even competitors—can come together for the advancement of knowledge.

You can see all of our findings within the study now. In the coming days and weeks we'll dive into deeper analysis as to what we can learn from these correlations.
Search Engine Ranking Correlation Study

Moz's Ranking Correlation Study measures which attributes of pages and websites are associated with higher rankings in Google's search results. This means we look at characteristics such as:
  • Keyword usage
  • Page load speed
  • Anchor text
  • ...and over 170 other attributes

To be clear, the study doesn't tell us if Google actually uses these attributes in its core ranking algorithm. Instead, it shows which features of pages and sites are most associated with higher rankings. It's a fine, but important, distinction.

While correlation studies can't prove or disprove which attributes Google considers in its algorithm, it does provide valuable hints. In fact, many would argue that correlation studies are even more important than causation when working with today's increasingly complex algorithms.

For the study, Dr. Peters examined the top 50 Google results of 16,521 search queries, resulting in over 700,000 unique URLs. You can read about the full methodology here.

Here's a sample of our findings:

Example: Page-Level Link-Based Features

The features in the chart below describe link metrics to the individual ranking page (such as number of links, PageRank, etc.) and their correlation to higher rankings in Google.

Despite rumors to the contrary, links continue to show one of the strongest associations with higher rankings out of all the features we studied. While this doesn't prove how Google uses links in its algorithm, this information combined with statements from Google and the observations of many professional marketers leads us to strongly believe that links remain hugely important for SEO.

Link-based features were only one of the features categories we examined. The complete correlation study includes 12 different categories of data

10 Ranking Factors summary findings

1. We continue to see lower correlations between on-page keyword use and rankings. This could likely be because Google is smarter about what pages mean (through related keywords, synonyms, close variants, and entities) without relying on exact keyword phrases. We believe matching user intent is of the utmost importance.
2. While page length, hreflang use, and total number of links all show moderate association with Google rankings, we found that using HTTPS has a very low positive correlation. This could indicate it's the "tie-breaker" Google claims. Negatively associated factors include server response time and the total length of the URL.
3. Despite rumors to the contrary, the data continues to show some of the highest correlations between Google rankings and the number of links to a given page.
4. While there exists a decent correlation between exact-match domains (domains where the keyword matches the domain exactly, e.g. and rankings, this is likely due to the prominence of anchor text, keyword usage, and other signals, instead of an algorithmic bias in favor of these domains.
5. Our study showed little relationship with the type of top-level domain (.com, .org, etc.) and rankings in Google.
6. While not quite as strong as page-level link metrics, the overall links to a site's root and subdomain showed a reasonably strong correlation to rankings. We believe links continue to play a prominent role in Google's algorithm.
7. Use of anchor text was another prominent feature of high-ranking results, with the number of unique domains linking with partial-match anchor text leading the way.
8.Always controversial, the number of social shares a page accumulates tends to show a positive correlation with rankings. Although there is strong reason to believe Google doesn't use social share counts directly in its algorithm, there are many secondary SEO benefits to be gained through successful social sharing.
9. Time until domain registration expiration was moderately correlated with higher rankings, while private registration showed a small negative correlation.
10. Engagement metrics from SimilarWeb showed that pages with lower bounce rates, higher pageviews, and better time-on-site metrics were associated with higher rankings.

Ranking Factors Expert Survey

While correlation data can provide valuable insight into the workings of Google's algorithm, we often learn much more by gathering the collective wisdom of search marketing experts working at the top of their game.

For this reason, every two years we conduct the Ranking Factors Expert Survey.

The survey itself is famously grueling–over 100 questions covering every aspect of Google's ranking algorithm. This year, we sent the invitation-only survey to 150 industry professionals.

Stay tuned for a deeper dive into the Expert Survey later this week. We're honored to have the participation of so many knowledgeable professionals. 

In the meantime, you can freely view all the findings and results right now:

Ranking Factors wouldn't be possible without the contribution of dozens of very talented people, but we'd especially like to thank Dr. Matt Peters, Kevin Engle, Rand Fishkin, Casey Coates, Trevor Klein, and Kelly Cooper for their efforts, along with our data partners and all the survey participants.

How to convert string variable to integer in PHP?

* eval — Evaluate a string as PHP code

Description: mixed eval ( string $code )

##eval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned. If there is a parse error in the evaluated code, eval() returns FALSE and execution of the following code continues normally. It is not possible to catch a parse error in eval() using set_error_handler().

* intval — Get the integer value of a variable

Description: int intval ( mixed $var [, int $base = 10 ] )

* floatval — Get float value of a variable

Description: float floatval ( mixed $var )

* boolval() - Get the boolean value of a variable
* intval() - Get the integer value of a variable
* strval() - Get string value of a variable
* settype() - Set the type of a variable
* JavaScript parseInt() Function - The parseInt() function parses a string and returns an integer.