Actualmente estoy trabajando en un sitio web que requiere que cargue la fuente de la imagen de una etiqueta desde un sitio web externo a través de jQuery o PHP para incrustar esa imagen en mi página, ¿hay alguna forma de hacer esto tal vez con XPath?
EDITAR: Según la investigación adicional que hice, tanto antes de hacer la pregunta aquí como después, ahora encontré la solución. Sergey Ligus me ha dado el enfoque correcto. El problema por el que file_get_contents no funcionó fue que la página parecía bloquear este tipo de solicitudes y tuve que falsificar un agente de usuario a través de stream_context_create.
Ejemplo:
$context = stream_context_create([ 'http' => [ 'user_agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)', ], ]); $html = file_get_contents('URL', false, $context); $dom = new DOMDocument(); $dom->loadHTML($html); $xpath = new DOMXPath($dom); $result = ''; foreach ($xpath->query('XPATH') as $child) { $result .= $dom->saveHTML($child); }
Encontré algo que podría responder a tu pregunta...
https://stackoverflow.com/questions/22580458/how-to-load-image-from-external-url-in-jquery-wordpress-theme
Si esto no responde a su pregunta, puedo decirle cómo hacerlo en Vanilla JS :)