메뉴 건너뛰기

프로그램언어

조회 수 30499 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
htmlentities해당하는 모든 문자를 HTML 엔티티로 변환
 
string htmlentities ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )

htmlentities()는 HTML 문자 엔티티에 존재하는 모든 문자를 엔티티로 변환하는 점을 제외하면, htmlspecialchars()와 완전히 동일합니다.

디코드(역변환)하려면 html_entity_decode()를 사용할 수 있습니다.
 
Example #1 htmlentities() ------------------------------------------------------------------------------------
<?php
$str 
"A 'quote' is <b>bold</b>"
;

// 출력: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str
);

// 출력: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($strENT_QUOTES);
?>

--------------------------------------------------------------------------------------------------------------
 
html_entity_decode모든 HTML 엔티티를 해당하는 문자로 변환
 
string html_entity_decode ( string $string [, int $quote_style [, string $charset ]] )

html_entity_decode()string 의 모든 HTML 엔티티를 해당하는 문자로 변환합니다. htmlentities()의 역함수입니다.

 

Example #1 HTML 엔티티 디코딩---------------------------------------------------------------------------------
<?php
$orig 
"I'll \"walk\" the <b>dog</b> now"
;
$a htmlentities($orig
);
$b html_entity_decode($a
);
echo 
$a
// I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
echo $b
// I'll "walk" the <b>dog</b> now

// PHP 4.3.0 이전 사용자는 이렇게 할 수 있습니다:
function unhtmlentities($string
)
{
    
// 숫자 엔티티 치환
    
$string preg_replace('~&#x([0-9a-f]+);~ei''chr(hexdec("\\1"))'$string
);
    
// 문자 엔티티 치환
    
$trans_tbl get_html_translation_table(HTML_ENTITIES
);
    
$trans_tbl array_flip($trans_tbl
);
    return 
strtr($string$trans_tbl
);
}
$c unhtmlentities($a
);
echo 
$c
// I'll "walk" the <b>dog</b> now
?>
----------------------------------------------------------------------------------------------------------------
 Note: trim(html_entity_decode('&nbsp;'));는 문자열을 빈 문자열로 변환하지 않습니다. 이는 기본값인 ISO-8859-1 문자셋에서 '&nbsp;' 엔티티가 (trim()에서 잘라내는) 아스키 코드 32

List of Articles
번호 제목 날짜 조회 수
20 CodeIgniter - DB오류체크, 디버깅 여부 설정 2021.03.29 496
19 Class를 이용한 DB Connection 소스 (Oracle, MyS 2014.02.27 30504
18 class_exists 클래스가 정의되었는지 확인 2016.12.23 19881
17 call_user_func 사용자가 정의한 함수를 호출하여 실행고자 할 때 사용 2016.12.23 21305
16 base64 인코딩/디코딩 함수의 특징 file 2018.02.09 13080
15 array_slice 배열의 일부를 추출 2016.12.23 20775
14 array_push 배열 끝에 하나 이상의 요소를 추가 2016.12.23 21604
13 array_key_exists 배열에서 key가 존재하는지 확인 2016.12.23 22206
12 array (배열) 2015.04.14 24904
11 AJAX를 활용하여 JSON 댓글 처리하기 (PHP) 2018.07.04 8456
10 AJAX로 해당 페이지에서 COOKIE 사용하기 2021.03.26 359
9 Ajax로 구연한 실시간 서버시간출력 file 2017.03.06 21032
8 ajax refresh 시키기(자동리플래쉬) with php file 2017.03.06 23185
7 addslashes 함수의 필요성 2015.04.14 24250
6 addslashes — 문자열을 슬래시로 인용 2016.12.23 23083
5 13자리 timestamp 생성하기 file 2020.09.28 652
4 $_SERVER변수 2014.02.27 24446
3 $_SERVER 환경변수 2016.09.21 33237
2 $_SERVER 함수 2016.12.23 23943
1 $_FILES 2016.12.23 23847
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved