How to remove html encoded in mysql data?

When I give a space in form and submit it into the database, I found the data has written with html encoded words which is actually a white space.

http://image.prntscr.com/image/f4232147a35240aabfe957fb0f27ba13.png

Can’t really help without seeing the code relevant to displaying the form, connecting to the database and storing the data.

else if(isset($_POST['description']) && isset($_POST['id'])){
    $description = trim($_POST['description']);
    $id = $_POST['id'];

    try{
        $createQuery = "UPDATE taskslists SET description = :desc
                        WHERE id = :id";
        
        $statement = $conn->prepare($createQuery);
        $statement->execute(array(":desc" => $description, ":id" => $id));

        if($statement){
            echo "Task description updated";
        }

    }catch(PDOException $ex){
        echo 'An error has occured ' . $ex->getMessage();
    }
}

Are you sure it’s an “html encoded” problem?

Seeing Ä Ä Ä makes me suspect it’s more likely a character set mismatch issue.

1 Like

Seems like the problem was solved by adding the “charset=utf8” in PDO define constant, now it is no longer showing that html encoded characters in the table. HOWEVER, how can I remove the space from the database table and in the form field, even I have given the trim(), you can see the 2nd line of the above code in the description code.

I think I have to give add trim too in UPDATE query but where?

trim works for only the beginning and end of strings. If there are multiple spaces within the string that you want to replace with single spaces I think passing the strings through str_replace would work. eg.

str_replace('  ', ' ', $string)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.