Home  >  Article  >  Backend Development  >  Regular expression example to convert dates in MM/DD/YYYY format to YYYY-MM-DD format_PHP Tutorial

Regular expression example to convert dates in MM/DD/YYYY format to YYYY-MM-DD format_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:26:48939browse



Regular expression

Return list


if(isset( $date)){
if ( ereg( "([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})" , $date, $regs ) ) {
echo $regs[0] . "The conversion result is: " . $regs[3] . "-" . $regs[1] . "-" . $regs[ 2];
} else {
echo "The date format of $date is wrong!
";}}?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531918.htmlTechArticleRegular expression returns list if(isset($date)){ if ( ereg( "([0-9 ]{1,2})/([0-9]{1,2})/([0-9]{4})", $date, $regs ) ) { echo $regs[0] . " The conversion result is: " . $regs[3] . "-" . $reg...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn