...

View Full Version : getting data from html tags?



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

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

Good luck!

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

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

bugster
03-07-2007, 09: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.

Inigoesdr
03-07-2007, 04: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