Chud37 Chud37 - 3 months ago 8
PHP Question

Echoing Value to HTML Text Input

Okay, so typically I would write the following:

<input type='text' class='form-control' name='name' value='<?=$user['name'];?>'>


However, because I am using
'
in my HTML, and if the name has a
'
in it, (i.e. the last name is
O'Brian
for instance) It doesn't echo correctly, because the value is ending the input abruptly.

Of course a simple solution is to use
"
quotation marks with my html, but that doesn't help - because what about when I want to echo quotation marks as well? What can I do?

Answer

Use <input type='text' class='form-control' name='name' value='<?php echo htmlentities($user['name'], ENT_QUOTES); ?>'>