Jump to content


Photo

Match html block


  • Please log in to reply
5 replies to this topic

#1 esiason14

esiason14
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 06 September 2006 - 10:22 PM

I normally don't do this, but when it come to regular expressions...I am lost. I've look at the tutorials and have tried and tried, but I cant seem to get it.

I'm trying to match a block of html like this:
                   <td width="50%" class="playerbio">
                     <b>Height/Weight: </b> 6-6/229<br> 
                     <b>Birthdate: </b> 04/22/1983<br> 
                     <b>Birthplace: </b> Fort Smith, AR, USA<br> 
                     
                   </td>

                   <td width="50%" class="playerbio">
                     <b>Team: </b> Jacksonville Jaguars<br> 
                     <b>College: </b> Arkansas<br>

anyone care to help. I will repay you with kind words  ;D

#2 Nicklas

Nicklas
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • Locationwww.nswardh.com

Posted 07 September 2006 - 12:12 AM

You want to match the text in bold?

#3 esiason14

esiason14
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 07 September 2006 - 01:08 AM

Sorry,

                   <td width="50%" class="playerbio">
                     <b>Height/Weight: </b> 6-6/229<br> 
                     <b>Birthdate: </b> 04/22/1983<br> 
                     <b>Birthplace: </b> Fort Smith, AR, USA<br> 
                     
                   </td>

                   <td width="50%" class="playerbio">
                     <b>Team: </b> Jacksonville Jaguars<br> 
                     <b>College: </b> Arkansas<br>

I want to match everything between the
</b> and <br> tags
....6-6/229, 04/22/1983, Fort Smith, AR, USA, Arkansas

#4 MaaSTaaR

MaaSTaaR
  • Members
  • PipPip
  • Member
  • 26 posts
  • LocationKuwait

Posted 07 September 2006 - 09:57 AM

try this :)

<?php

	$string = '<td width="50%" class="playerbio">
                     <b>Height/Weight: </b> 6-6/229<br> 
                     <b>Birthdate: </b> 04/22/1983<br> 
                     <b>Birthplace: </b> Fort Smith, AR, USA<br> 
                     
                   </td>

                   <td width="50%" class="playerbio">
                     <b>Team: </b> Jacksonville Jaguars<br> 
                     <b>College: </b> Arkansas<br>';
                     
	$search = "~</b>\s*(.*?)\s*<br>~ise";
	$replace = "replace('\\1')";
	
	$do_search = preg_replace($search,$replace,$string);
	
	function replace($text)
	{
		echo $text . '<br />';
	}

?>

try this page : http://gnosis.cx/pub...xpressions.html it's great :)
Sorry for my bad English, it's not my mother language and I am still learning it :)

#5 Nicklas

Nicklas
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • Locationwww.nswardh.com

Posted 07 September 2006 - 01:24 PM

preg_match_all('/(?<=<\/b>).*?(?=<br( \/)?>)/is', $string, $matches);
print_r($matches);


#6 esiason14

esiason14
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 07 September 2006 - 02:57 PM

Thanks for the help, guys!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users