当前位置:编程学习 > php >>

正则表达式例子:将MM/DD/YYYY格式的日期转换为YYYY-MM-DD格式

<html>
<head><title>正则表达式</title></head>
<body>
<a href="./">返回列表</a>
<form action="<? echo $PHP_SELF; ?>" method="post">
请输入MM/DD/YYYY格式的日期:
<input type="text" name="date" value="<? echo $date; ?>">
<input type="submit" value="转换为YYYY-MM-DD格式">
</form>
<?
if(isset($date)){
if ( ereg( "([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $date, $regs ) ) {
echo $regs[0] . "的转换结果为:" . $regs[3] . "-" . $regs[1] . "-" . $regs[2];
} else {
echo "$date 的日期格式不对!<br>";
}
}
?>
</body>
</html>


补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,