Home >Backend Development >PHP Tutorial >Regular expression example: Convert date in MM/DD/YYYY format to YYYY-MM-DD format_PHP tutorial

Regular expression example: Convert date in MM/DD/YYYY format to YYYY-MM-DD format_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:21:281975browse


Regular Expression

Return to list


Please enter the date in MM/DD/YYYY format:



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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532483.htmlTechArticlehtml headtitle regular expression/title/head body a href="./"Return list/a form action= "? echo $PHP_SELF; ?" method="post" Please enter the date in MM/DD/YYYY format: input type="text" name...
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