Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 没有得到想要的结果_Php_Special Characters_Htmlspecialchars - Fatal编程技术网

Php 没有得到想要的结果

Php 没有得到想要的结果,php,special-characters,htmlspecialchars,Php,Special Characters,Htmlspecialchars,我在下面有一个函数,它的结果仍然是string(13)“hell'o”o 而不是特殊字符 功能: private function makeHTMLSpecial($input) { return htmlentities(trim($input), ENT_QUOTES); } 代码: $new_descriptionCheck = $this->input->post('desc'); $new_description

我在下面有一个函数,它的结果仍然是
string(13)“hell'o”o
而不是特殊字符

功能:

private function makeHTMLSpecial($input)
        {
            return htmlentities(trim($input), ENT_QUOTES);
        }
代码:

$new_descriptionCheck = $this->input->post('desc');

$new_description      = $this->makeHTMLSpecial($new_descriptionCheck);  

你的括号对吗

private function makeHTMLSpecial($input)
{
    return htmlentities(trim($input), ENT_QUOTES);
}

正在测试字符串长度

$string = "hell'o\"o";
var_dump($string); // string 'hell'o"o' (length=8)
var_dump(htmlspecialchars($string)); // string 'hell'o"o' (length=13)

如果您添加更多的codeCurious,它将非常有用。
hell'o“o
有8个符号,但它表示长度为13。也许它只是在做它应该做的事情,但是你在浏览器中观察输出却看不到。
string(13)
——它给出的正是想要的结果。同意,在运行
htmlspecialchars()
后,字符串长度13是正确的,因为
占用了6个字符(请参阅我的更新)谢谢,它仍然没有解决这个问题-我已经更新了代码,遗憾的是没有那么多代码可以继续