#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0

    remove <span></span>


    I would like to remove all span html tags (and the contents in it) and the end of span too. <span xxx...></span>
    I also need to remove chunk in between <p xxxx....> tags - just leaving <p>.

    I would prefer two separate operations so that I can learn to do this on my own.
    What is the best way to do this?
    ----------
    Update: I found the answer on Stack Overflow
    '/<span[^>]+\>/i' and '/<\/span\>/i'
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,487
    Rep Power
    1876
    Well regex is going to be the wrong tool for the job.

    You'll find it hard to exclude all the places where span can appear (such as the body of your text) from actual spans you want to remove.

    Use a tool which knows how to navigate HTML/XML - https://en.wikipedia.org/wiki/XPath
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    14
    Rep Power
    0
    I don't share your skepticism. What is needed is to find every "<span", erase it and everything until you reach a ">" and erase it. I don't know regex well enough to do it but it would be something like "<span[*]>".
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,487
    Rep Power
    1876
    Go ahead and try it on the HTML of your original post.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo