PHP 如何用转义字符替换客户文本区域的撇号 [英] PHP How to replace customers text area apostrophes with a escape character

查看:38
本文介绍了PHP 如何用转义字符替换客户文本区域的撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一周前我试过问这个问题,但没有得到答案.希望这次能解释得更好.

I tried asking this question a week ago but got no answer. Hoping to explain it better this time.

我的客户可以在 textarea 中输入任何内容,我将其保存到 MySQL 表中.

My customer can input anything into a textarea and I am saving that to a MySQL table.

我怎样才能用双撇号替换他们的所有撇号,这样我就不会得到错误的查询?

how can I replace all of their apostrophes with a double apostrophe so I don't get a bad query?

我尝试了以下方法没有用.

I tried the following it didn't work.

$description = str_replace("''", "'", $description);

推荐答案

嗨 Landon 你试过这个 'mysqli_real_escape_string' 函数吗?

Hi Landon have you tried this 'mysqli_real_escape_string' function ?

字符串 mysqli_real_escape_string ( mysqli $link , 字符串 $escapestr )

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

示例如下:

$link = mysqli_connect("localhost", "my_user", "my_password", "world");

$lastname  = "O'Reilly";
$_lastname =mysqli_real_escape_string($link, $lastname);

http://us3.php.net/mysql-real-escape-string

这篇关于PHP 如何用转义字符替换客户文本区域的撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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