从字符串叶子中删除撇号39

时间:2013-10-17 12:04:34

标签: php replace special-characters

我试图从字符串中删除特殊字符,准备在URL中使用。这是我现在的代码:

public function __construct($string) {

    $remove = array("!", "'", '"', "(", ")", ";", "@", "&", "=", "$", ",", "/", "?", "%", "#", "[", "]");

    var_dump($string);
    $this->string = $string;
    $this->string = str_replace($remove, "", $this->string);
    //$this->string = preg_replace("/[\s_\-:+]+/", "-", strtolower($this->string));
    var_dump($this->string);

}

这就是它的输出:

string(16) "Today's Quiz" string(13) "Today39s Quiz"

这没有任何意义......在任何时候我都不会转换特殊字符或任何东西,那么39来自哪里?我无法追踪它。

1 个答案:

答案 0 :(得分:5)

如字符串的长度所示,您的输入实际上是:

Today's Quiz
1234567890123456 -> 16 characters

由于您正在修剪& #;个字符,因此结果是剩​​余的39