[英]Escape string in mssql/php
I want to insert html-code in database. 我想在数据库中插入HTML代码。 How can I correctly escape string?
如何正确转义字符串?
$html = '<tag>';
$sql = 'UPDATE table SET text = ? WHERE id = 1';
$stmt = sqlsrv_prepare($conn, $sql, array(&$html));
sqlsrv_execute($stmt);
This code throw error: Incorrect syntax near '<'. 这段代码抛出错误:'<'附近的语法不正确。
Escape the HTML with 使用以下命令转义HTML
htmlspecialchars($html)
This function changes <
to the HTML code for <
此函数将
<
更改为<
的HTML代码<
This will fix you problem. 这将解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.