preg_match help please

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

preg_match help please

Post by jasondavis »

Code: Select all

<td id="ProfileGeneral" width="175" bgcolor="#d5e8fb" style="WORD-WRAP: break-word"></style>hoho"
<br>
Male<br>22 years old<br>Lake Helen, FL<br>
<br>
Last Login: comming soon<br>
</td></tr><tr><td colspan="4">
<a href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewPicture&friendID=10021628">
view more pics (10)</a>
can someone help me I need to get the proper preg_match to extract the Male or Female of pages that will be just like this code

I have this for other items from the same page this code is on

Code: Select all

preg_match("/<span class=\"nametext\">(.*)<\/span>/", $html, $msname);
				preg_match("/<td class=\"text\" width=\"193\" bgcolor=\"#ffffff\" height=\"75\" align=\"left\">\"(.*)\"<br>/", $html, 	$msdata);
				preg_match("/has <span class=\"redbtext\">(\d+)<\/span> friends/", $html, $msfc);
				preg_match("/(\d+) years old/", $html, $msyo);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

preg_match('#<\s*br(?:\s*/)?>\s*((?:fe)?male)\s*<\s*br(?:\s*/)?>#is',$html,$sex);
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

Post by jasondavis »

you're awsome thanks
jasondavis
Forum Commoner
Posts: 60
Joined: Sat Feb 04, 2006 5:35 pm

Post by jasondavis »

one small problem it works but I guess some pages must be different because its picking up other data for some users, any solution to this?
Image

looking at the profile page of that first entry in the pic above the source area looks like this

Code: Select all

<td class="text" width="193" bgcolor="#ffffff" height="75" align="left">"The Kaz"<br>
			    <br>
			    Male
			    <br>
			    26 years old
Post Reply