Extract data between tags

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bootzwiz
    New Member
    • Jan 2007
    • 14

    #1

    Extract data between tags

    Hi,
    I want to extract data between tags. For example i have following code

    <span class="t_t_12_b _b">Cast</span><span class="t_t_12_b ">: <a href="/test/">Mel Gibb</a></span>

    I want to extract data between <span class="t_t_12_b _b"></span> and <span class="t_t_12_b "></span> and show it as following

    Cast : Mel Gibb

    Please advice how to do it.If possible please provide code.

    Rajesh
  • b1randon
    Recognized Expert New Member
    • Dec 2006
    • 171

    #2
    Originally posted by bootzwiz
    Hi,
    I want to extract data between tags. For example i have following code

    <span class="t_t_12_b _b">Cast</span><span class="t_t_12_b ">: <a href="/test/">Mel Gibb</a></span>

    I want to extract data between <span class="t_t_12_b _b"></span> and <span class="t_t_12_b "></span> and show it as following

    Cast : Mel Gibb

    Please advice how to do it.If possible please provide code.

    Rajesh
    Are you trying to do this in PHP or JavaScript? It sounds more like a JS task, unless there's a reason you're doing it in PHP. Please tell us a bit more.

    Comment

    • bootzwiz
      New Member
      • Jan 2007
      • 14

      #3
      Originally posted by b1randon
      Are you trying to do this in PHP or JavaScript? It sounds more like a JS task, unless there's a reason you're doing it in PHP. Please tell us a bit more.
      Yes iam trying to do in php .

      i trying to extract some content from a page and show it in some other page.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        If you know regular expressions, use the preg_replace function. Decide what the form of the tags will be. Will it always be a span tag? If you don't know the class name, you could just search for the end of the tag (>) and from there get your value up to </span>. Use the function to match these tags and remove them by replacing them with the empty string.

        Comment

        • bootzwiz
          New Member
          • Jan 2007
          • 14

          #5
          Originally posted by acoder
          If you know regular expressions, use the preg_replace function. Decide what the form of the tags will be. Will it always be a span tag? If you don't know the class name, you could just search for the end of the tag (>) and from there get your value up to </span>. Use the function to match these tags and remove them by replacing them with the empty string.
          Yes its always span tag and class names are same for entire page. I am able to get content for single span.Here is my code

          [PHP]preg_match_all( "/<span class=\"style1\ ".*span>/", $html, $matches);[/PHP]

          But i dont know how to get for two span tags.

          <span class="style1"> Cast</span><span class="style2"> : <a href="/test/">Mel Gibb</a></span>

          Please suggest.

          Comment

          Working...