我想將字符串「T恤背心」改爲「TShirts背心」。我曾經嘗試這樣做:PHP替換字符串中的內容
$item['menu_3'] = str_ireplace("T Shirts Vests", "TShirts", $item['menu_3']);
但str_ireplace
似乎並不能夠搞定。我應該怎麼做?
我想將字符串「T恤背心」改爲「TShirts背心」。我曾經嘗試這樣做:PHP替換字符串中的內容
$item['menu_3'] = str_ireplace("T Shirts Vests", "TShirts", $item['menu_3']);
但str_ireplace
似乎並不能夠搞定。我應該怎麼做?
$item['menu_3'] = str_ireplace("T Shirts Vests","TShirts Vests", $item['menu_3']);
str_replace
也會順便工作。
$str = "T Shirts Vests";
$str[strpos($str, " ")] = '';
這將取代每個空間,所以'T恤衫背心'變成'TShirtsVests',我不認爲是他在追求的。 – 2012-02-08 22:21:33
thx @Sam,我最初認爲str_replace(count)的最後一個參數告訴PHP停止一定數量的替換。但實際上,這是一個變量,用於獲取* set *的函數。固定。 – 2012-02-08 22:31:38
你得到的輸出是什麼?爲什麼你使用str_ireplace而不是str_replace?你需要不區分大小寫嗎? – 2012-02-08 22:18:08
您輸入的代碼非常有意義,並且沒有任何錯誤,除了您將「TShirts」替換爲* entire *字符串「T恤背心」。如果不知道'$ item ['menu_3'])''的內容,我們無法幫助您。請編輯您的問題以包含它。 – meagar 2012-02-08 22:18:28