$pieces = explode ("年",$date_chinese);
$year = trim($pieces [0]);
$pieces = explode ("月",$pieces [1]);
$month = trim($pieces [0]);
$pieces = explode ("日",$pieces [1]);
$day = trim($pieces [0]);$DATETIMES = "$year-$month-$day";
可以再检查一下是否正确,写成一个函数!
$year = trim($pieces [0]);
$pieces = explode ("月",$pieces [1]);
$month = trim($pieces [0]);
$pieces = explode ("日",$pieces [1]);
$day = trim($pieces [0]);$DATETIMES = "$year-$month-$day";
可以再检查一下是否正确,写成一个函数!
$DateTimes = $Y."-".$M."-".$D//插入的部分我就写了//取出
$sql = "Select * from table where ...";
$arr = mysql_fetch_array(mysql_query($sql));
$Y = substr($arr[0],0,3);
$M = substr($arr[0],5,2);
$D = substr($arr[0],7,2);
$sql = "Select 日期字段 from table where ...";
substr 是什么函数?可以再解析下吗?
你也可以解析下explode和trim的意思用法吗?
(PHP 3, PHP 4 )substr -- Return part of a string
Description
string substr ( string string, int start [, int length])
substr() returns the portion of string specified by the start and length parameters. If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth. 例子 1. Basic substr() usage<?php
$rest = substr("abcdef", 1); // returns "bcdef"
$rest = substr("abcdef", 1, 3); // returns "bcd"
$rest = substr("abcdef", 0, 4); // returns "abcd"
$rest = substr("abcdef", 0, 8); // returns "abcdef"// Accessing via curly braces is another option
$string = 'abcdef';
echo $string{0}; // returns a
echo $string{3}; // returns d
?>
$Y = substr($str,0,4);//取出$str 的前四个字符(第0个到第3个)
$M = substr($str,4,2);//从$str的第四个字符(是1)开始取2个(第四个、第五个)
$D = substr($str,6,2);
echo $Y.'年'.$M.'月'.$D.'日';
echo '<br>';
$str='2003-12-05';
$Y = substr($str,0,4);
$M = substr($str,5,2);
$D = substr($str,8,2);
echo $Y.'年'.$M.'月'.$D.'日';
echo '<br>';
?>