Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

503
Views
PHP Cómo evitar esta advertencia: DOMDocument::loadHTML(): Carácter no válido en CDATA

Estoy tratando de recopilar información de un servicio web, pero tengo problemas con la sección CDATA de una página, porque todo sale bien cuando uso algo como esto:

 $url = 'http://www.example.com'; $content = file_get_contents($url); $doc = new DOMDocument(); $doc->loadHTML($content); foreach($doc->getElementsByTagName('h3') as $subtitle) { echo $subtitle->textContent; //The output is the Subtitle/s. }

Pero cuando la página contiene secciones CDATA hay un problema con este error en la línea $doc->loadHTML($content).

 Warning: DOMDocument::loadHTML(): Invalid char in CDATA

He visto aquí una solución que traté de implementar sin éxito.

 function sanitize_html($content) { if (!$content) return ''; $invalid_characters = '/[^\x9\xa\x20-\xD7FF\xE000-\xFFFD]/'; return preg_replace($invalid_characters,'', $content); } $url = 'http://www.example.com'; $content = file_get_contents($url); $cleanContent = sanitize_html($content); $doc = new DOMDocument(); $doc->loadHTML($cleanContent); //Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity

Pero tengo este otro error:

 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity

¿Cuál podría ser una buena manera de lidiar con las secciones CDATA de una página? Saludos.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Intente agregar PCLZIP antes de cargar IOFactory como se muestra:

 require_once '/Classes/PHPExcel.php'; \PHPExcel_Settings::setZipClass(\PHPExcel_Settings::PCLZIP);
about 4 years ago · Santiago Trujillo Report

0

La solución es - reemplazar el símbolo & con &amp; o si debe tener eso y tal como está entonces, puede incluirlo en: <![CDATA[ - ]]>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!