2014-03-06 4 views
0

이 코드의 html_entity_decode에 PHP 매뉴얼 항목에서 적응()왜이 html_decode_entities를 사용하지 않습니까?

protected function decode($data) 
{ 
    $data = html_entity_decode($data, ENT_QUOTES,'UTF-8'); 
    //echo $data; 
    return $data; 
} 
protected function decode_data($data) 
{ 

    if(is_object($data) || is_array($data)){ 
     array_walk_recursive($data,array($this,'decode')); 
    }else{ 
     $data = html_entity_decode($data, ENT_QUOTES,'UTF-8'); 
    } 
    return $data; 
} 

데이터가 포함되어있는 경우 는 IT가 Children's

답변

1

문제는 html_entity_decode 함께 할 수 없다 디코딩되지 않습니다 Children's 같은 값, ' 같은 견적 엔티티 만 디코드하려는 경우이 작업을 올바르게 수행 할 수 있습니다.

대신 문제는 array_walk_recursive을 올바르게 사용하지 않았다는 것입니다. 다음에서 나는 익명 함수를 사용하고 참조로 값을 전달 : 작은 따옴표 문자로

function decode_data($data) 
{ 
    if(is_object($data) || is_array($data)){ 
     // &$val, not $val, otherwise the array value wouldn't update. 
     array_walk_recursive($data, function(&$val, $index) { 
      $val = html_entity_decode($val, ENT_QUOTES,'UTF-8'); 
     }); 
    }else{ 
     $data = html_entity_decode($data, ENT_QUOTES,'UTF-8'); 
    } 
    return $data; 
} 
$array = [ 
    "Children's", 
    "Children's", 
]; 
print_r(decode_data($array)); 

출력 모두 어린이의를하지 엔티티있다.

+0

감사합니다. – codecowboy

관련 문제