htmlentities 함수
htmlentities 함수는 문자를
해당하는 HTML 엔티티로 변환합니다. 더 나은 이해를 위해 예제를 확인하세요.
이 함수는 htmlspecialchars와 유사하지만,
HTML 엔티티가 존재하는 모든 문자를 변환한다는 점에서 다릅니다.
구문
htmlentities(string $string, int $flags = ENT_COMPAT, ?string $encoding = null, bool $double_encode = true): string
예제
태그가 포함된 문자열을 변환해 봅시다:
<?php
$str = '<b>text</b>';
$res = htmlentities($str);
echo $res;
?>
코드 실행 결과:
'<b>text</b>'
예제
앰퍼샌드(&)가 포함된 문자열을 변환해 봅시다:
<?php
$str = 'test: &';
$res = htmlentities($str);
echo $res;
?>
코드 실행 결과:
'test: &'
함께 보기
-
역방향 작업을 수행하는 함수
html_entity_decode -
유사한 작업을 수행하는 함수
htmlspecialchars