Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/09/2015, 08:50
wmmb
 
Fecha de Ingreso: septiembre-2015
Mensajes: 6
Antigüedad: 8 años, 7 meses
Puntos: 0
Pregunta Respuesta: Caracteres Unicodes y PHP

He implementado también esta estrategia:

Código PHP:
$response_body '{"author_name": "Contranalisis Psiconeurociencia", "height": 356, "thumbnail_height": 360, "author_url": "https:\/\/www.youtube.com\/user\/potencialhumanotv", "width": 474, "thumbnail_url": "https:\/\/i.ytimg.com\/vi\/IyjWqRixa0U\/hqdefault.jpg", "type": "video", "html": "\u003ciframe width=\"474\" height=\"356\" src=\"https:\/\/www.youtube.com\/embed\/IyjWqRixa0U?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "thumbnail_width": 480, "provider_name": "YouTube", "title": "El Potencial Humano con Leonardo Stemberg (15 de Julio 2015)", "provider_url": "https:\/\/www.youtube.com\/", "version": "1.0"}'

function replace_unicode_escape_sequence($match) {
        return 
mb_convert_encoding(pack('H*'$match[1]), 'UTF-8''UCS-2BE');
    }
    
function 
replace_unicode_callback($str) {
        return 
preg_replace_callback('/\\\\u([0-9a-f]{4})/i''replace_unicode_escape_sequence'$str);
    }

echo 
replace_unicode_callback(trim$response_body ) ) 
Si a la función replace_unicode_escape_sequence() le hago un "echo" al mb_convert_encoding(), imprime muy bien los <>, pero el reamplazo al final no llega a hacerse. insisto que es muy extraño... a alguien le pasó alguna vez?