addslashes, stripslashes, htmlspecialchars

Language/PHP 2010. 5. 27. 09:54

No. 28

함수명

addslashes

의미

작은 따옴표(') 와 큰 따옴표(") 역 슬래쉬(\)와 같은 특정문자 앞에 역슬래쉬(\) 문자를 붙인다.

형식

string addslashes ( string $str )

매개변수

$str  : 변환할 문자열 문자

예)

<?

$comment = "안녕하세요 '공군식' 입니다.!";

echo "addslashes() 함수 호출전 : ".$comment."<p>";

 

$comment = addslashes($comment);

echo "addslashes() 함수 호출후 : ".$comment;

?>

결과

addslashes() 함수 호출전 : 안녕하세요 '공군식' 입니다.!

addslashes() 함수 호출후 : 안녕하세요 \'공군식\' 입니다.!

 

No. 29

함수명

stripslashes

의미

addslashes() 함수를 통해 역슬래쉬가 된 문자를 원상태로 돌린다.

형식

string stripslashes ( string $str )

매개변수

$str  : 변환할 문자열 문자

예)

<?

$comment = "안녕하세요 '공군식' 입니다.!";

echo "addslashes() 함수 호출전 : ".$comment."<p>";

$comment = addslashes($comment);

echo "addslashes() 함수 호출후 : ".$comment."<p>";

$comment = stripslashes($comment);

echo "stripslashes() 함수 호출후 : ".$comment;

?>

결과

addslashes() 함수 호출전 : 안녕하세요 '공군식' 입니다.!

addslashes() 함수 호출후 : 안녕하세요 \'공군식\' 입니다.!

stripslashes() 함수 호출후 : 안녕하세요 '공군식' 입니다.!

 

No. 30

함수명

htmlspecialchars

의미

HTML코드를 문자열 소스 그대로 출력한다.

형식

string htmlspecialchars ( string $string [, int $quote_style = ENT_COMPAT [, string $charset [, bool $double_encode = true ]]] )

매개변수

$string : 문자값 // $quote_style  $charset  $double_encode  각종 옵션값

예)

<?

$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);

echo $new;

?>

결과

<a href='test'>Test</a>

'Language > PHP' 카테고리의 다른 글

print_r(), var_dump(), var_export  (0) 2010.05.28
mysql_free_result  (0) 2010.05.28
preg_replace  (0) 2010.05.27
IF의 다른 표현 (Alternative syntax for IF statements): IF(): ... ENDIF;  (0) 2010.05.26
외부 링크 방지  (0) 2010.05.25
: