HOWTO · PHP

PHP의 마법 인용문

이 기사에서는 PHP의 adslashes() 함수에 대해 설명합니다.

이 기사에서는 PHP의 addslashes() 기능에 대해 설명합니다. 미리 정의된 문자 앞에 백슬래시가 있는 문자열을 반환합니다.

미리 정의된 문자는 다음과 같습니다.

  1. 작은따옴표 '
  2. 큰따옴표 ''
  3. 백슬래시 \
  4. 무효

PHP의 마법 인용문

데이터베이스 및 쿼리에 저장할 문자열을 준비할 때 이 기능을 실제로 사용할 수 있습니다.

PHP의 매직 따옴표가 감가 상각되기 전에 magic_quotes_gpc가 기본적으로 켜져 있었습니다. 기본적으로 $_GET/$_POST/$_COOKIES/$_REQUEST에서 addslashes() 기능을 실행하는 데 사용됩니다.

우리는 항상 이미 이스케이프된 문자열을 확인합니다. 이러한 문자열에서 addslashes() 함수를 실행하면 이중 이스케이프가 발생합니다.

get_magic_quotes_gpc()를 사용하여 문자열이 이스케이프되었는지 확인하십시오.

통사론:

addslashes(string)

아래 코드는 addslashes() 기능이 작동하는 방식을 보여줍니다.

<?php
// PHP code to show the
// working of the addslashes() function

// String
$str = addslashes('delftstack provides "coding" lessons');

// prints the escaped string
echo($str);
?>

출력:

delftstack provides \"coding\" lessons

예 2:

<?php
$str = "My name's Chris.";
echo $str . " This is not secure in a database query.<br>";
echo addslashes($str) . " This is secure in a database query.";
?>

출력:

My name's Chris. This is not secure in a database query.
My name\'s Chris. This is secure in a database query.

addslashes() 함수는 addcslashes() 함수와 다릅니다.