메뉴 건너뛰기

프로그램언어

조회 수 30406 추천 수 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
번호 제목 날짜 조회 수
220 JSON and JavaScript usage 2014.03.26 19064
219 자릿수만큼 앞에 0 붙이기 2017.03.07 19027
218 링크를 걸때 http 처리방법 2016.12.23 19019
217 정규 표현식 검색과 치환 (preg_replace) 2016.12.23 19012
216 디렉토리 안의 파일의 내용들을 읽는 예 2016.12.23 19012
215 mysql_result — 결과 데이터를 반환 2016.12.23 18958
214 문자열 뒤집기 (strrev) 2016.12.23 18950
213 문자열 찾기 (strstr) 2016.12.23 18907
212 도메인 앞에 자동으로 WWW를 붙이는 방법 2017.03.07 18885
211 문자열 추출하기 (substr) 2016.12.23 18867
210 두 날짜 사이의 차이 구하기 2017.03.07 18866
209 로그인페이지에서 온 경우/로그인한 페이지로 이동 2016.12.23 18847
208 문자열 치환 (str_replace) 2016.12.23 18812
207 mysql_affected_rows — 최근 MySQL 작업으로 변경된 행 개수를 얻음 2016.12.23 18806
206 mysql_insert_id 2016.12.23 18750
205 네이버 지도 API 연동 PHP 소스 2017.03.06 18635
204 mysql_real_escape_string 이진 데이터를 입력할 경우 이 함수를 사용해야 함 2016.12.23 18635
203 PHP 날짜/시간 정리 2017.03.07 18629
202 오류 메시지 출력(alert) 및 페이지 이동(refresh) 관련 2017.03.06 18568
201 잡다한 php 2017.03.06 18502
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved