首页 > 语言 > PHP > 正文

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

2024-09-04 11:47:09
字体:大 中 小
来源:转载
供稿:网友
  1. <html> 
  2. <head><title>正则表达式</title></head> 
  3. <body> 
  4. <a href="./">返回列表</a> 
  5. <form action="<? echo $PHP_SELF; ?>" method="post"> 
  6. 请输入MM/DD/YYYY格式的日期: 
  7. <input type="text" name="date" value="<? echo $date; ?>"> 
  8. <input type="submit" value="转换为YYYY-MM-DD格式"> 
  9. </form> 
  10. <? 
  11. if(isset($date)){ 
  12.     if ( ereg( "([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $date, $regs ) ) { 
  13.         echo $regs[0] . "的转换结果为:" . $regs[3] . "-" . $regs[1] . "-" . $regs[2]; 
  14.     } else { 
  15.         echo "$date 的日期格式不对!<br>"; 
  16.     } 
  17. } 
  18. ?> 
  19. </body> 
  20. </html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表