本函數將 unescaped_string 中的特殊字符轉義,並計及連接的當前字符集,因此可以安全用於 mysql_query()。
註: mysql_real_escape_string() 並不轉義 % 和 _。
例子 1. mysql_real_escape_string() 例子
<?php
$item = "Zak's and Derick's Laptop";
$escaped_item = mysql_real_escape_string($item);
printf ("Escaped string: %s\n", $escaped_item);
>以上例子將產生如下輸出:
Escaped string: Zak\'s and Derick\'s Laptop