라이브러리
[PHP] mb_decode_numericentity - HTML 숫자 문자열 참조를 문자로 디코딩
PHP의 `mb_decode_numericentity` 함수는 HTML 엔티티를 숫자로 변환하는 데 사용되는 함수입니다. 이 함수는 `mb_convert_encoding` 함수와 유사하지만, HTML 엔티티를 숫자로 변환하는 데 특화되어 있습니다.
mb_decode_numericentity 함수의 사용법
`mb_decode_numericentity` 함수는 다음 형식으로 사용됩니다.
#hostingforum.kr
php
string mb_decode_numericentity ( string $string , array $dec , string $encoding )
- `$string` : 변환할 문자열입니다.
- `$dec` : HTML 엔티티를 숫자로 변환할 때 사용하는 규칙을 정의하는 배열입니다.
- `$encoding` : 문자열의 인코딩입니다.
예제
다음 예제는 `mb_decode_numericentity` 함수를 사용하여 HTML 엔티티를 숫자로 변환하는 방법을 보여줍니다.
#hostingforum.kr
php
// HTML 엔티티를 숫자로 변환할 규칙을 정의하는 배열
$dec = array(
0x00A0 => array(0x00A0, 0x00A0), // non-breaking space
0x00A6 => array(0x00A6, 0x00A6), // pilcrow
0x2010 => array(0x2010, 0x2010), // figure space
0x2011 => array(0x2011, 0x2011), // thin space
0x2012 => array(0x2012, 0x2012), // en space
0x2013 => array(0x2013, 0x2013), // em space
0x2014 => array(0x2014, 0x2014), // en quad
0x2015 => array(0x2015, 0x2015), // em quad
0x2018 => array(0x2018, 0x2018), // left single quotation mark
0x2019 => array(0x2019, 0x2019), // right single quotation mark
0x201C => array(0x201C, 0x201C), // left double quotation mark
0x201D => array(0x201D, 0x201D), // right double quotation mark
0x202F => array(0x202F, 0x202F), // narrow no-break space
);
// HTML 엔티티를 숫자로 변환
$html = " &pilcrow;&figspace; ‘’“” ";
$decoded = mb_decode_numericentity($html, $dec, 'UTF-8');
// 결과를 출력
echo $decoded;
이 예제에서는 HTML 엔티티를 숫자로 변환할 때 사용하는 규칙을 정의하는 배열 `$dec`를 정의하고, `mb_decode_numericentity` 함수를 사용하여 HTML 엔티티를 숫자로 변환한 후 결과를 출력합니다.
참고
- `mb_decode_numericentity` 함수는 PHP 5.2.0부터 사용할 수 있습니다.
- `$dec` 배열의 키는 HTML 엔티티의 유니코드 값이어야 합니다.
- `$dec` 배열의 값은 두 개의 유니코드 값으로 구성됩니다. 첫 번째 값은 HTML 엔티티를 숫자로 변환할 때 사용하는 유니코드 값이고, 두 번째 값은 변환 결과의 유니코드 값입니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.