str_replace没有正确替换单引号

时间:2015-11-18 05:54:35

标签: php dom

我很难通过str_replace替换单引号。这是我的代码

function cleanstring($string) {

   $unwanted = array("’","'",";",".",":","’");
   echo "cleaned: ".str_replace($unwanted, "", $string);
}

仍然输出

cleaned: Bob’s Burgers Season 1 Episode 1
cleaned: Bob's Burgers Season 2

注意:上面的字符串中有两种类型的引号。

任何人都告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

试试这个......

   <?php

$data="Bob’s Burgers Season 1 Episode 1";
$data1="Bob's Burgers Season 2";

    echo str_replace( array( "'","’" ),'',$data );
    echo "\n";
   echo str_replace( array( "'" ,"’" ),'',$data1 );


   echo "------------------------------------------";

   function cleanstring($string) {


   echo str_replace( array( "'" ,"’" ),'',$string);
}
 echo "\n";
cleanstring($data);
 echo "\n";
cleanstring($data1);

   ?>

演示:https://eval.in/470891