I <span> what I <span>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexander Ross

    I <span> what I <span>

    I have an html snippet, and I want to remove any <span> tags that have a
    specific attribute (class=none)

    ex. The quick brown <span class="animal"> fox</span> jumped <span
    class="none">ov er</span> the lazy dog

    should become

    The quick brown <span class="animal"> fox</span> jumped over the lazy dog

    I'm guessing i need to use reg expressions, but I can't quite grasp how to
    do this.

    Thoguhts? Questions? Comments? Jokes? Humourous musings?

    Alex



  • Justin Koivisto

    #2
    Re: I &lt;span&gt; what I &lt;span&gt;

    Alexander Ross wrote:
    [color=blue]
    > I have an html snippet, and I want to remove any <span> tags that have a
    > specific attribute (class=none)
    >
    > ex. The quick brown <span class="animal"> fox</span> jumped <span
    > class="none">ov er</span> the lazy dog
    >
    > should become
    >
    > The quick brown <span class="animal"> fox</span> jumped over the lazy dog
    >
    > I'm guessing i need to use reg expressions, but I can't quite grasp how to
    > do this.
    >
    > Thoguhts? Questions? Comments? Jokes? Humourous musings?[/color]

    <?php
    $str='The quick brown <span class="animal"> fox</span> jumped <span
    class="none">ov er</span> the lazy dog';
    echo htmlentities($s tr),'<br>';
    echo
    htmlentities(pr eg_replace('`<s pan[^>]*class=(\'|")?n one\1[^>]*>(.*)</span>`isU',"$2" ,$str));
    ?>

    --
    Justin Koivisto - spam@koivi.com

    Comment

    • Chung Leong

      #3
      Re: I &lt;span&gt; what I &lt;span&gt;

      "Alexander Ross" <aross@dosometh ing.org> wrote in message
      news:A12Xc.4611 5$rP2.24877@hyd ra.nntpserver.c om...[color=blue]
      > I have an html snippet, and I want to remove any <span> tags that have a
      > specific attribute (class=none)
      >
      > ex. The quick brown <span class="animal"> fox</span> jumped <span
      > class="none">ov er</span> the lazy dog
      >
      > should become
      >
      > The quick brown <span class="animal"> fox</span> jumped over the lazy dog
      >
      > I'm guessing i need to use reg expressions, but I can't quite grasp how to
      > do this.[/color]

      RegExp won't work in situations where there are nested spans. Might be safer
      to just take out the 'class="none"'.


      Comment

      • Tim Tyler

        #4
        Re: I &lt;span&gt; what I &lt;span&gt;

        Alexander Ross <aross@dosometh ing.org> wrote or quoted:
        [color=blue]
        > I have an html snippet, and I want to remove any <span> tags that have a
        > specific attribute (class=none)
        >
        > ex. The quick brown <span class="animal"> fox</span> jumped <span
        > class="none">ov er</span> the lazy dog
        >
        > should become
        >
        > The quick brown <span class="animal"> fox</span> jumped over the lazy dog
        >
        > I'm guessing i need to use reg expressions, but I can't quite grasp how to
        > do this.
        >
        > Thoguhts? Questions? Comments? Jokes? Humourous musings?[/color]

        An HTML parser is needed to do it properly.

        Saxy:


        XML_HTMLSax:

        --
        __________
        |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply.

        Comment

        Working...