2012-07-31 69 views
-3

我有一個字符串,它是一個日期,其格式爲2012/04/19。我想用-替換/標誌,所以它的格式爲2012-04-19日期字符串替換

我試過str_replace但它不起作用。

str_replace('2012/04/19','/'); 
+5

你可以閱讀[文件](http://php.net/manual/ en/function.str-replace.php)。沒有理由不這樣做。 – Esailija 2012-07-31 18:02:46

+3

RTFM:http://php.net/manual/en/function.str-replace.php – Matt 2012-07-31 18:03:13

回答

1

你沒有正確調用str_replace

$date = str_replace('/', '-', '2012/04/19'); 
4

您正在尋找

str_replace("/", "-", "2012/04/19"); 
2

str_replace的語法是str_replace(find,replace,string,count)

所以,你想使用

str_replace('/','-','2012/04/19');