2014-12-13 1 views
-2

html_entity_decode()는 HTML 엔터티를 반환하며 문자는 사용할 수 없습니다. html_entity_decode()가 작동하지 않습니다. (PHP)

<meta http-equiv="Content-Type" content="text/html charset=UTF-8"> 
 
<?php 
 

 
$code='&#97'; // It's a code of 'a' UTF-8 character. 
 

 
$char = html_entity_decode($code, ENT_COMPAT, $encoding = 'UTF-8'); 
 

 
/* 
 
Now $char must contains 'a' value, but it contains '&#97'; 
 

 
You can check this by following tests 
 
*/ 
 

 
var_dump('&#97' === 'a');  // bool(false), of course. 
 
var_dump('&#97' === $code); // bool(true) 
 
var_dump('&#97' === $char); // bool(true) BUT MUST BE FALSE 
 
var_dump($code === $char);  // bool(true) BUT MUST BE FALSE 
 

 
// Or this: 
 

 
echo str_replace('&', '', $char); // it must print 'a', but it print '#97'
내 경우에는 아무것도하지 않고이 기능을 것 같은데. 무엇이 잘못 되었나요?

+0

글자 참조에 ';':':'a '이 없습니다. – Gumbo

+0

PHP는 파이썬이 아니며 명명 된 매개 변수가 없습니다. '$ encoding = 'UTF-8'은 아마도 당신이 생각하는대로하지 않을 것입니다. 함수 호출은 단순히'html_entity_decode ($ code, ENT_COMPAT, 'UTF-8')'이어야합니다. – deceze

답변

0

&#97은 ''UTF-8 문자 '의 코드가 아닙니다. "

그러나 &#97;입니다. 이를 사용하면 코드가 예상대로 작동합니다.