Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting data from html tags?

    Hello,
    I was wondering if someone can help with figure out how to pull content from between a specified html tag and store it in a variable in php?

    So for example, given this html string and the span tag and it's class is always consistent:

    <span class="myClassName">W00t!</span>

    How can i extract the "W00t!" part and store it in a variable ($myVariable)? Thanks!

  • #2
    New Coder
    Join Date
    Jul 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll want to look into regular expressions.

    Good luck!

  • #3
    New Coder
    Join Date
    Mar 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, i found regex after posting this. Looking into it now.

    http://www.regular-expressions.info/

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, i cant seem to figure this out or am just getting it wrong. Can anyone help me out, this is what i have:

    $myVar = "<span class=\"nametext\"[^>]+>(.*)</[^>]+>";
    echo $myVar[0];

    It doesnt print anything out.
    Last edited by bugster; 03-07-2007 at 09:45 AM.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    $count preg_match('/<span class="myClassName">(.*)<\/span>/s''<span class="myClassName">W00t!</span>'$matches);
    echo 
    $matches[0]; 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •