0

I'm trying to remove special characters from a string, preparing it for use in a URL. This is my code as of now:

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);

}

And this is what it outputs:

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

That makes no sense... At no point do I convert special characters or anything, so where does the 39 come from? I can't track it down.

4

1 回答 1

5

从字符串的长度可以看出,你的输入其实是:

Today's Quiz
1234567890123456 -> 16 characters

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

于 2013-10-17T12:07:18.723 回答