我有一個字符串,它是一個日期,其格式爲2012/04/19
。我想用-
替換/
標誌,所以它的格式爲2012-04-19
日期字符串替換
我試過str_replace
但它不起作用。
str_replace('2012/04/19','/');
我有一個字符串,它是一個日期,其格式爲2012/04/19
。我想用-
替換/
標誌,所以它的格式爲2012-04-19
日期字符串替換
我試過str_replace
但它不起作用。
str_replace('2012/04/19','/');
你沒有正確調用str_replace
。
$date = str_replace('/', '-', '2012/04/19');
您正在尋找
str_replace("/", "-", "2012/04/19");
str_replace的語法是str_replace(find,replace,string,count)
。
所以,你想使用
str_replace('/','-','2012/04/19');
每the documentation,你需要的代碼是
str_replace("/", "-", "2012/04/19");
你可以閱讀[文件](http://php.net/manual/ en/function.str-replace.php)。沒有理由不這樣做。 – Esailija 2012-07-31 18:02:46
RTFM:http://php.net/manual/en/function.str-replace.php – Matt 2012-07-31 18:03:13