Jump to content

Archived

This topic is now archived and is closed to further replies.

esiason14

Match html block

Recommended Posts

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:
[code]                  <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>[/code]

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

Share this post


Link to post
Share on other sites
Sorry,

[code]                  <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>[/code]

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

Share this post


Link to post
Share on other sites
try this :)

[code=php:0]
<?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 />';
}

?>
[/code]

try this page : http://gnosis.cx/publish/programming/regular_expressions.html it's great :)

Share this post


Link to post
Share on other sites
[code=php:0]preg_match_all('/(?<=<\/b>).*?(?=<br( \/)?>)/is', $string, $matches);
print_r($matches);[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.