PHP str_replace无法正常工作

时间:2016-01-20 18:10:38

标签: php str-replace

puts "Elements are: #{array.to_sentence(last_word_connector: ', ')}."

我需要以下结果:replace.com,replace.net,replace.org,replace.info,replace.biz

2 个答案:

答案 0 :(得分:0)

作为PHP manual says

  

str_ireplace - str_replace()的不区分大小写的版本。

所以你应该使用str_ireplace

$str_replace = str_ireplace($lowerCase, $replace, $my_string);

但请注意,该字符大小写由服务器的语言环境设置定义,该设置会影响包含非ASCII字符的字符串。

您也可以使用strtolower

$str_replace = str_replace($lowerCase, $replace, strtolower($my_string));

答案 1 :(得分:0)

strtolower() $ my_string并为您的结果编写代码。 str_replace - 用替换字符串替换所有出现的搜索字符串(PHP 4,PHP 5,PHP 7)

$replace = 'replace';
$my_string = ' abC.com, Abc.net, aBc.org, ABC.info, aBC.biz '; 
$lowerCase = 'abc';
$str_replace = str_replace($lowerCase, $replace, strtolower($my_string));
echo $str_replace;
相关问题