PHP / Reference / addslashes()
개요
- addslashes() 함수는 PHP에서 문자열에 특수 문자를 이스케이프 처리할 때 사용됩니다. 이 함수는 데이터베이스 쿼리에 사용될 때 SQL 인젝션 공격을 방지하는 데 도움이 됩니다.
- PHP 4 이상에서 사용할 수 있습니다.
문법
addslashes( string )
다음 문자 앞에 백슬래시를 추가합니다.
- single quote (')
- double quote (")
- backslash (\)
- NULL
예제
<!doctype html> <html lang="ko"> <head> <meta charset="utf-8"> <title>PHP</title> <style> * { font-family: "Consolas", monospace; font-size: 24px; } </style> </head> <body> <p>'PHP → <?php echo addslashes( "'PHP" ); ?></p> <p>"PHP → <?php echo addslashes( '"PHP' ); ?></p> <p>\PHP → <?php echo addslashes( '\PHP' ); ?></p> </body> </html>
참고
- 백슬래시를 제거하는 함수는 stripslashes()입니다.