Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
Php cómo configurar datos en cadena usando html id

Tengo texto html largo. Pásalo de js a php. Necesito cambiar el contenido de ID con mi texto.

Intenté hacerlo así:

 $html = new DOMDocument(); $html->loadHTML($codeText); $html->getElementById('second_head')->nodeValue = $leadAddressTemplate; $html->getElementById('rechnung_div')->nodeValue = $rehnungTemplate; $res = $html->saveHTML();

Funciona pero tiene un problema: mi sistema <> chars reemplaza a &lt; y &gt; y el sistema agrega <html><body> a mi texto.

¿Cómo puedo arreglarlo? Tal vez hay algunas banderas para ello?

Por ejemplo, la entrada es:

 <tr> <td colspan="2" class="invoice-products" width="100%"> <div id="rechnung_div"></div> </td> </tr>

Y trata de hacerlo:

 $html->getElementById('rechnung_div')->nodeValue = '<p>It is rechnung</p>';

Como resultado tengo esto:

 <tr> <td colspan="2" class="invoice-products" width="100%"> <div id="rechnung_div">&lt;p&gt;It is rechnung&lt;/p&gt;</div> </td> </tr>

Ahora puedo poner por ejemplo

elemento:

 $appended = $html->createElement('p', 'It is rechnung'); $html->getElementById('rechnung_div')->nodeValue = ''; $rechnung_div->appendChild($appended);

Pero, ¿cómo insertar una tabla, por ejemplo, así?

 <table> <tbody><tr> <td style="width: 40%;vertical-align: baseline;"><h1 id="invoice_type">Rechnung</h1> <p id="invoice_title">gtrgtrgrtgtr</p></td> <td style="width: 60%;text-align: right;vertical-align: bottom;"><h1>&nbsp;</h1><p id="invoice_nummer"></p></td> </tr> </tbody> </table>

No puedo hacerlo con la función appendChild()

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Juntando las notas de los comentarios:

 $parent = <<<_E_ <tr> <td colspan="2" class="invoice-products" width="100%"> <div id="rechnung_div"></div> </td> </tr> _E_; $template = <<<_E_ <p>I am a template</p> _E_; $temp = new DOMDocument(); $temp->loadHTML($template, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); // get the document's root element $temp_root = $temp->documentElement; $html = new DOMDocument(); $html->loadHTML($parent, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); // import the template into the current document $node = $html->importNode($temp_root, true); $html->getElementById('rechnung_div')->appendChild($node); echo $html->saveHTML();

Producción:

 <tr> <td colspan="2" class="invoice-products" width="100%"> <div id="rechnung_div"><p>I am a template</p></div> </td> </tr>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda