开发者

PHP How to I make my textinput accept single quote or Double quotes

开发者 https://www.devze.com 2023-04-09 19:54 出处:网络
How do I make my textinput accept apostrophe or double quotes? Everytime a user type\'s in this one: John\'s Birthday, I store this one in the database using mysql_real_escape_string().

How do I make my textinput accept apostrophe or double quotes?

Everytime a user type's in this one: John's Birthday, I store this one in the database using mysql_real_escape_string().

What I wanted to do in here is to retrieve it in my text input. I tried this one

<input type='text' name='title' value='<?php echo $values->title; ?>' />

The problem here is it removes the single quote and the letters that comes after the quote. I tried to changed the value= '' from value="" but what if a user types a word that has开发者_如何学JAVA example this one: "You and Me". The problem is still in there.

I was thinking to use str_replace in doing this one and replace the ' into `, but again I was thinking that maybe there's an easy way to do it.

Any help would be greatly appreciated.

Thanks!


Check out this: http://www.primitivetype.com/articles/quotes_inputs.php

Basically, call htmlentities on your output before placing it in the form's value. This will turn characters like ' into the html equivalent &#39;.

e.g.

<input ... value='<?php echo htmlentities($values->title, ENT_QUOTES); ?>' />


You can replace double quotes with &quot;. &#39; for single quotes.


Replace single quote with &#145;

0

精彩评论

暂无评论...
验证码 换一张
取 消