Chud37 Chud37 - 1 year ago 103
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
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download