Search code examples
phpspecial-charactershtmlspecialchars

htmlentities not giving wanted result


I have the following function below how ever the result is still giving me string(13) "hell'o"o" and not the special chars

Function:

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

Code:

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

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

Solution

  • is your bracketing correct?

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

    Testing string length...

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