htmlentities 함수

htmlentities 함수는 문자를 해당하는 HTML 엔티티로 변환합니다. 더 나은 이해를 위해 예제를 확인하세요.

이 함수는 htmlspecialchars와 유사하지만, HTML 엔티티가 존재하는 모든 문자를 변환한다는 점에서 다릅니다.

구문

phphtmlentities(string $string, int $flags = ENT_COMPAT, ?string $encoding = null, bool $double_encode = true): string

예제

태그가 포함된 문자열을 변환해 봅시다:

php<?php
  $str = '<b>text</b>';
  $res = htmlentities($str);
  
  echo $res;
?>

코드 실행 결과:

php'<b>text</b>'

예제

앰퍼샌드(&)가 포함된 문자열을 변환해 봅시다:

php<?php
  $str = 'test: &';
  $res = htmlentities($str);
  
  echo $res;
?>

코드 실행 결과:

php'test: &'

함께 보기