如何在 PHP 中保存这个字符串? [英] How to save this string in PHP?

查看:41
本文介绍了如何在 PHP 中保存这个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 PHP 中保存这个字符串时:

When I save this string in PHP:

John: "Yes you can".

在我的数据库中保存为:

In my database is saved as:

John: \

我怎样才能用(显然不删除")保存这些字符串.这是我的php代码:

How can I save these strings with " ( without deleting " obviously ). This is my php code:

$titlepost= mysql_real_escape_string($_POST['title']);
$query = "INSERT INTO `titles` (`title`) VALUES ( '".$titlepost."')";
$res = mysql_query($query) or die("Failed".mysql_error() );

echo $titlepost;

output: 
John: \\

表格:

$title = mysql_real_escape_string($_GET['title']);

<form method="post" action="title.php?done=yes" enctype="multipart/form-data">
<input type="text" size="25" name="title" <?php echo "value=\"".$title."\""; ?> > 
<input id="starit" name="submit" value="titleit" type="submit" />
</form>

推荐答案

您的问题与 PHP 或 MysQL 无关.

Your problem has nothing to do with PHP or MysQL.

它就像非常简单的 HTML 语法规则一样愚蠢.很明显,代码

It is as silly as very simple HTML syntax rule. It is quite obviously that the code

<input value="John: "YES you can>

将仅显示引用的John:"部分.为了使它正确,必须在值中编码特殊符号

will show only quoted "John: " part. To make it correct, one have to encode special symbols in the value

$titlepost = htmlspecialchars($titlepost,ENT_QUOTES);
?>
<input type="text" name="title" value="<?=$titlepost?>">

至于斜线 - 这是愚蠢的过度引用问题.只需引用一次您的字符串,并确保您已关闭 magic_quotes_gpc

As for the slashes - it is silly excessive quoting issue. just quote your strings only once and make sure you have magic_quotes_gpc turned off

这篇关于如何在 PHP 中保存这个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆