View Full Version : getting data from html tags?

03-07-2007, 02:37 AM
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!

03-07-2007, 04:12 AM
You'll want to look into regular expressions.

Good luck!

03-07-2007, 05:01 AM
thanks, i found regex after posting this. Looking into it now.


03-07-2007, 08:05 AM
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.

03-07-2007, 03:56 PM
$count = preg_match('/<span class="myClassName">(.*)<\/span>/s', '<span class="myClassName">W00t!</span>', $matches);
echo $matches[0];

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum