Foros del Web » Programando para Internet » PHP »

Reemplazar Etiquetas

Estas en el tema de Reemplazar Etiquetas en el foro de PHP en Foros del Web. Hola, tengo el siguiente texto: Código HTML: <span class= "underline" > It was popularised in the 1960s with the release of Letraset sheets containing Lorem ...
  #1 (permalink)  
Antiguo 13/09/2011, 08:59
 
Fecha de Ingreso: agosto-2008
Mensajes: 108
Antigüedad: 15 años, 8 meses
Puntos: 0
Reemplazar Etiquetas

Hola, tengo el siguiente texto:

Código HTML:
<span class="underline"> It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>Lorem Ipsum is simply dummy text of the printing and typesetting industry.<br /></span><span class="italic">Lorem Ipsum is simply dummy text of the printing and typesetting industry.<br /></span><span class="underline">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</span><br /><br /><span class="italic bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.<br /></span><span class="bold italic">Lorem Ipsum is simply dummy text of the printing and typesetting industry.<br /></span><span class="underline italic bold">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</span> 
Aquí hay diferente tipos de span, lo que quiero hacer es reemplazar las etiquetas span por etiquetas xml, por ejemplo: <span class="bold italic">prueba</span> por esto: <b><i>prueba</i></b>

Alguien tiene alguna idea de como se hace?...
  #2 (permalink)  
Antiguo 13/09/2011, 09:01
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Reemplazar Etiquetas

str_replace o preg_replace.
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #3 (permalink)  
Antiguo 13/09/2011, 09:29
 
Fecha de Ingreso: agosto-2008
Mensajes: 108
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Reemplazar Etiquetas

ok, pero como hago para saber cual </span> cierra a su determinado span, teniendo en cuanta que pueden haber span sobre span.
  #4 (permalink)  
Antiguo 13/09/2011, 09:32
Avatar de abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 10 meses
Puntos: 1517
Respuesta: Reemplazar Etiquetas

Podrías hacer algo así, pasa por el área de aportes para que veas un tema que te puede ayudar a desenvolverte con expresiones regulares.
Código PHP:
Ver original
  1. <?php
  2. $str_to_edit = '<span class="underline"> It was popularised in the 1960s with the release of Letraset
  3.     sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like
  4.     Aldus PageMaker including versions of Lorem Ipsum.</span>Lorem Ipsum is simply dummy text of the
  5.     printing and typesetting industry.<br /></span><span class="italic">Lorem Ipsum is simply dummy
  6.     text of the printing and typesetting industry.<br /></span><span class="underline">Lorem Ipsum is
  7.     simply dummy text of the printing and typesetting industry.</span><br /><br />
  8.     <span class="italic bold">Lorem Ipsum is simply dummy text of the printing and typesetting
  9.     industry.<br /></span><span class="bold italic">Lorem Ipsum is simply dummy text of the printing
  10.     and typesetting industry.<br /></span><span class="underline italic bold">Lorem Ipsum is simply
  11.     dummy text of the printing and typesetting industry.</span>';
  12. $find = array('<span class="underline">', '</span>');
  13. $replace = array('<b><i>', '</i></i>');
  14. $str = preg_replace('/<span.*?>(.+?)<\/span>/is', '<b><i>$1</i></b>', $str_to_edit);
  15. echo $str;
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos
  #5 (permalink)  
Antiguo 13/09/2011, 10:11
 
Fecha de Ingreso: agosto-2008
Mensajes: 108
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Reemplazar Etiquetas

ok, voy a probarlo, gracias.
  #6 (permalink)  
Antiguo 14/09/2011, 10:30
 
Fecha de Ingreso: agosto-2008
Mensajes: 108
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Reemplazar Etiquetas

Lo he probado pero no da el resultado deseado, toma en cuenta el primer span que encuentra, y ese span pertenece a otro.

Etiquetas: etiquetas, reemplazar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:36.