2010-09-04 70 views
1

我一直在使用str_replace更換最常見的words..and由於某種原因,它除了更換瓶蓋每一個字母一個可愛的小問題here..i'm。str_replace函數只是返回帽

爲example..if我有下面的代碼

$str ="Fat string of Text.";  
$commonwords = array('fat','of','random'); 
$cleantext = str_replace($commonwords,'',$str); 

echo $cleantext;

它將呼應.. F T

任何想法,我做錯了什麼..提前

感謝

和oh..i試圖str_ireplace ..但沒有

+0

爲我工作。 'str_replace()函數'給我'脂肪串Text.'和'str_ireplace()'給我'字符串Text.'。你確定你向我們展示了實際的代碼嗎? – BoltClock 2010-09-04 02:41:23

回答

4

這回聲「胖字符串文本」

PHP安裝可能是錯誤或您的發佈代碼,不會不完全匹配程序正在運行

此外,str_ireplace回聲「字符串文本」

+0

found that proble'm .. 我的數組中的一些單詞就像 - >我,不能< - 撇號正在使問題..感謝您的幫助 – andrewk 2010-09-04 03:04:17

+0

是的,逃避你的撇號: ) – 2010-09-04 03:07:12

0

不能重現於PHP 5.3.3。我得到:

php > $str ="Fat string of Text."; 
php > $commonwords = array('fat','of','random'); 
php > $cleantext = str_replace($commonwords,'',$str); 
php > echo $cleantext; 
Fat string Text. 
php > $cleantext = str_ireplace($commonwords,'',$str); 
php > echo $cleantext; 
string Text. 

與預期的一樣。