Amir
Amir

Reputation: 3

fix html Symbol Entities with php

I have one form for adding book to library (database) ...

Its my form:

<form>
    <input type="text" name="title">
    <input type="text" name="text">
    <input type="submit">
</form>

If I use the form 'Words', the form will not be submited

I think i want this code in php :

str_replace("'", "&#39;", '".$_POST['title']."');

But it very very hard for all characters

Upvotes: 0

Views: 107

Answers (1)

Mauricio Florez
Mauricio Florez

Reputation: 1132

You can use this statement to replace all POST items

foreach ($_POST as &$post){
    $post = htmlentities($post, ENT_QUOTES);
}

Or use PDO quote method to escape the quotes

foreach ($_POST as &$post)
{
    $post = $your_pdo_connection->quote($post);
}

Upvotes: 1

Related Questions