함수들

addslashes()함수

상감자 2018. 1. 22. 10:29

string addslashes ( string $str )


single quote (')

double quote (")

backslash (\)

NUL (the NUL byte)


위의  기호들을 \을 붙여서 return해주는 함수로, 대개 sql injection등을 방어할 때에 효과적으로 쓰인다.


예)

"'hello world"'   ->  \"\'hello world\'\"


<?php
$str = "Who's Peter Griffin?";
echo $str . " This is not safe in a database query.<br>";
echo addslashes($str) . " This is safe in a database query.";
?>



--->


Who's Peter Griffin? This is not safe in a database query.
Who\'s Peter Griffin? This is safe in a database query.