메뉴 건너뛰기

프로그램언어

조회 수 30408 추천 수 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 array_slice 배열의 일부를 추출 2016.12.23 20775
219 [PHP] 게시판 글쓰기와 이미지 파일 DB 저장 및 불러오기 예제 2017.02.19 35886
218 PHP에서 데이터를 엑셀(Excel)로 저장 2017.02.19 18428
217 파일업로드 2017.02.19 19352
216 phpexcel을 이용한 PHP로 엑셀파일 읽기와 생성 file 2017.03.06 22787
215 PHPExcel 클래스를 이용해 Excel 2007~2010 의 xlsx 파일 읽기 (100만 행 까지) 2017.03.06 21695
214 CodeIgniter에서 PHPExcel 사용하기 file 2017.03.06 20289
213 PHP로 엑셀 자료 MySQL에 넣기 2017.03.06 17875
212 메일주소의 골뱅이를 그림처리하기 2017.03.06 15508
211 오류 메시지 출력(alert) 및 페이지 이동(refresh) 관련 2017.03.06 18568
210 ajax refresh 시키기(자동리플래쉬) with php file 2017.03.06 23185
209 Ajax로 구연한 실시간 서버시간출력 file 2017.03.06 21031
208 지엠 웹에디터 v1.1 (저작권표시없음)| file 2017.03.06 17109
207 text파일에 한줄씩 내용추가하기 2017.03.06 17535
206 PHP 만년달력 소스 2017.03.06 17063
205 PHP EXCEL export시 시트 이름 지정하여 여러 시트에 데이터 쓰기 2017.03.06 18266
204 PHP의 유동변수!? - $a1 ~ $a2 같은 형식의 변수를 반복문 돌릴때... 2017.03.06 16610
203 PHP에서 Excel 파일을 만들 수 있는 PHPExcel file 2017.03.06 17112
202 php로 db 컨트롤 1 2017.03.06 15769
201 php 문자열관련 함수 2017.03.06 15580
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved