The exact characters that are escaped by this function are the null byte (0), newline (\n), carriage return (\r), backslash (\), single quote ('), double quote (") and substiture (SUB, or \032).
mysql_escape_string
(PHP 4 >= 4.0.3, PHP 5)
mysql_escape_string — mysql_query에서 문자열을 escape하기위해 사용
설명
string mysql_escape_string
( string $unescaped_string
)
이 함수는 unescaped_string을 mysql_query()에 안전하도록 escape시킨다. 이 함수의 사용은 권장하지 않는다.
이 함수는 접속 핸들러를 이용하여 현재 문자셋을 따라서 문자를 escape하는 것만 제외하고는 mysql_real_escape_string()와 비슷하다. mysql_escape_string()는 접속 핸들러를 인수로 갖지 않으며, 현재 문자셋에 대해 고려하지 않는다.
인수
- unescaped_string
-
Escape할 문자열.
반환값
Escape된 문자열.
변경점
| 버전 | 설명 |
|---|---|
| 5.3.0 | E_DEPRECATED 주의가 발생합니다. |
| 4.3.0 | 이 함수의 사용은 권장하지 않는다. 대신, mysql_real_escape_string()를 사용하라. |
예제
Example #1 mysql_escape_string() 예제
<?php
$item = "Zak's Laptop";
$escaped_item = mysql_escape_string($item);
printf("Escaped string: %s\n", $escaped_item);
?>
위 예제의 출력:
Escaped string: Zak\'s Laptop
주의
Note:
mysql_escape_string()은 %와 _를 escape하지 않는다.
참고
- mysql_real_escape_string() - mysql_query에서 특수 문자열을 이스케이프하기위해 사용
- addslashes() - 문자열을 슬래시로 인용
- magic_quotes_gpc 지시어.
s dot marechal at jejik dot com
26-Jan-2011 02:37
as_lh
26-Mar-2010 05:05
it seems the function changes the character encoding of the string.
I get utf-8 encoded string and my mysql database is set to utf-8 as well.
If i just write the data to the database it works perfectly fine, if i use this function, it changes the encoding and therefore stores the wrong characters.
Seems like a bug to me.
