最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PHP How to I make my textinput accept single quote or Double quotes - Stack Overflow

programmeradmin1浏览0评论

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 es after the quote. I tried to changed the value= '' from value="" but what if a user types a word that has 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!

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 es after the quote. I tried to changed the value= '' from value="" but what if a user types a word that has 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!

Share Improve this question asked Sep 29, 2011 at 1:16 PinoyStackOverflowerPinoyStackOverflower 5,30218 gold badges66 silver badges134 bronze badges 1
  • 3 Duplicate of stackoverflow./questions/1771798/… – nnnnnn Commented Sep 29, 2011 at 1:21
Add a ment  | 

3 Answers 3

Reset to default 4

Check out this: http://www.primitivetype./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)

  1. 暂无评论