Names like O'Quinn cause form problems

I have a admin tools page that allows me to pull up the account of any registered user. At the top of the page is the person’s name:

Peter O’Quinn

The code to produce this at the top is:

<th colspan=‘2’><h3>$firstname $lastname</h3></th>

Further down the page I have editable fields where I can make changes, if needs be, to their name and other information. Here is the code:

<input class=form name=‘firstname’ id=‘firstname’ size=50 maxlength=50 value=‘$lastname’>

However, the letters after the ’ are removed and so the name shows up in the input field as:


How come the name displays correct at the top of my page, but inside an input field, it doesn’t seem to like apostrophes?


<input class=form name='firstname' id='firstname' size=50 maxlength=50 value='$lastname'>

How would that code look if you replace $lastname with O’Quinn? (which is exactly what PHP does)

<input class=form name='firstname' id='firstname' size=50 maxlength=50 value='O'Quinn'>

See the problem now?

I am pretty sure you want to check out the htmlentities() function. See here

Or htmlspecialchars()

You need htmlentities($str, ENT_QUOTES)

htmlentities($str, ENT_QUOTES) did the trick. Thanks!