Jump to content

Recommended Posts

I'm trying to get a listing of transactions from this page:

[a href=\"http://www.sportsline.com/mlb/transactions\" target=\"_blank\"]http://www.sportsline.com/mlb/transactions[/a]


I'm using this, which returns the info all jumbled together (see below)

[code]<?php

/*** Load the page here ***/

$input = file_get_contents("http://www.sportsline.com/mlb/transactions");

// *** Finding the team transactions between href tags ***/

$trans= preg_match("@<a[\s]+href=/mlb/teams/transactions/(.*)>(.*)</a>@", $input, $matches);


// Did we find a match?
if ($trans = true) {

// Here it is
echo '<br />' . strip_tags($matches['1']) . '<br>';

}

?>[/code]


Output looks like this:

[code]Washington NationalsRecalled OF Ryan Church and INF Brendan Harris from New Orleans of the PCL. Optioned OF Brandon Watson and C Wiki Gonzalez to New Orleans.Wednesday, April 12, 2006Arizona DiamondbacksPlaced LHP Terry Mulholland on the 15-day DL. Purchased the contract of RHP Casey Daigle from Tucson of the PCL.Atlanta BravesRecalled INF Tony Pena from Richmond of the IL.Baltimore OriolesRecalled RHP Chris Britton from Bowie of the Eastern League. Optioned RHP Cory Morris to Ottawa of the IL.Boston Red SoxAgreed to terms with OF Coco Crisp on a three-year contract extension through 2009. Activated LHP David Wells from the 15-day DL. Placed RHP David Riske on the 15-day DL, retroactive to April 5.Milwaukee BrewersClaimed RHP Vince Perkins off waivers from Toronto.Seattle MarinersActivated OF Matt Lawton. Designated C Guillermo Quiroz for assignment. Optioned RHP Jeff Harris to Tacoma of the PCL. Recalled C Rene Rivera from Tacoma.Tampa Bay Devil RaysPlaced 3B Aubrey Huff on the 15-day DL.Texas RangersPlaced 2B Ian Kinsler on the 15-day DL. Activated OF Gary Matthews Jr. from the 15-day DL. Activated INF Marshall McDougall from the 15-day DL and optioned him to Oklahoma of the PCL.Toronto Blue JaysAssigned C Jason Phillips outright to Syracuse of the IL.[/code]

I'm trying to get it where I can show each transaction, by team the specified date. Can someone point me in the right direction and/or offer an example/pointers. THanks
Link to comment
https://forums.phpfreaks.com/topic/7417-regex-help/
Share on other sites

[!--quoteo(post=364836:date=Apr 14 2006, 11:58 AM:name=esiason14)--][div class=\'quotetop\']QUOTE(esiason14 @ Apr 14 2006, 11:58 AM) [snapback]364836[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm trying to get a listing of transactions from this page:

[a href=\"http://www.sportsline.com/mlb/transactions\" target=\"_blank\"]http://www.sportsline.com/mlb/transactions[/a]
I'm using this, which returns the info all jumbled together (see below)

[code]<?php

/*** Load the page here ***/

$input = file_get_contents("http://www.sportsline.com/mlb/transactions");

// *** Finding the team transactions between href tags ***/

$trans= preg_match("@<a[\s]+href=/mlb/teams/transactions/(.*)>(.*)</a>@", $input, $matches);
// Did we find a match?
if ($trans = true) {

// Here it is
echo '<br />' . strip_tags($matches['1']) . '<br>';

}

?>[/code]
Output looks like this:

[code]Washington NationalsRecalled OF Ryan Church and INF Brendan Harris from New Orleans of the PCL. Optioned OF Brandon Watson and C Wiki Gonzalez to New Orleans.Wednesday, April 12, 2006Arizona DiamondbacksPlaced LHP Terry Mulholland on the 15-day DL. Purchased the contract of RHP Casey Daigle from Tucson of the PCL.Atlanta BravesRecalled INF Tony Pena from Richmond of the IL.Baltimore OriolesRecalled RHP Chris Britton from Bowie of the Eastern League. Optioned RHP Cory Morris to Ottawa of the IL.Boston Red SoxAgreed to terms with OF Coco Crisp on a three-year contract extension through 2009. Activated LHP David Wells from the 15-day DL. Placed RHP David Riske on the 15-day DL, retroactive to April 5.Milwaukee BrewersClaimed RHP Vince Perkins off waivers from Toronto.Seattle MarinersActivated OF Matt Lawton. Designated C Guillermo Quiroz for assignment. Optioned RHP Jeff Harris to Tacoma of the PCL. Recalled C Rene Rivera from Tacoma.Tampa Bay Devil RaysPlaced 3B Aubrey Huff on the 15-day DL.Texas RangersPlaced 2B Ian Kinsler on the 15-day DL. Activated OF Gary Matthews Jr. from the 15-day DL. Activated INF Marshall McDougall from the 15-day DL and optioned him to Oklahoma of the PCL.Toronto Blue JaysAssigned C Jason Phillips outright to Syracuse of the IL.[/code]

I'm trying to get it where I can show each transaction, by team the specified date. Can someone point me in the right direction and/or offer an example/pointers. THanks
[/quote]


What is it that you are trying to match using preg_match()? Try escaping the special characters. Add a \ before the special characters to match the character literally.

Link to comment
https://forums.phpfreaks.com/topic/7417-regex-help/#findComment-27211
Share on other sites

[!--quoteo(post=365038:date=Apr 15 2006, 06:11 AM:name=bonaparte)--][div class=\'quotetop\']QUOTE(bonaparte @ Apr 15 2006, 06:11 AM) [snapback]365038[/snapback][/div][div class=\'quotemain\'][!--quotec--]
What is it that you are trying to match using preg_match()? Try escaping the special characters. Add a \ before the special characters to match the character literally.
[/quote]


Does the below code make sense?

<?php

/*** Load the page here ***/

$input = file_get_contents("http://www.sportsline.com/mlb/transactions");

// *** Finding the team transactions between href tags ***/

$trans= preg_match("/div.class=SLTables1>.+/", $input, $matches);


// Did we find a match?
if ($trans = true) {

// Here it is
//echo '<br />' . strip_tags($matches['1']) . '<br>';
print_r($matches);

}

?>
Link to comment
https://forums.phpfreaks.com/topic/7417-regex-help/#findComment-27212
Share on other sites

Okay, first of all in your code you are doing if($trans = true), which is going to SET $trans to true so it's ALWAYS going to be true. When evaluating a variable on it's contents, please remember to use "==" not "=". Anyway, onto the good stuff. I've re-written your code pretty much completely and have come up with my own solution to your problem, giving you the date, the team, and the article all seperate. Please see below:

[code]
$input = file_get_contents("http://www.sportsline.com/mlb/transactions");
preg_match_all("#(?<=<font class=bg0font>)(?P<D>.+)(?=</font>)(?P<C>.+)(?=</tr><tr align=left class=bg0>)#U", $input, $match);

foreach($match['D'] as $key => $date) {
        printf("DATE: %s\n", $date);
        $trans = preg_match_all("#(?:<a href=/mlb/teams/transactions/[A-Z]{2,3}>)(?P<T>.+)(?:</a></td><td  align=left>)(?P<I>.+)(?:</td>)#U", $match['C'][$key], $matches);

        foreach($matches['T'] as $key => $team) {
                printf("Team: %s Story: %s \n", $team, $matches['I'][$key]);
        }
}
[/code]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
%php -f test.php
DATE: Saturday, April 15, 2006
Team: Boston Red Sox Story: Placed LHP David Wells on the 15-day DL. Called up RHP Jermaine Van Buren from Pawtucket of the IL.
Team: Chicago Cubs Story: Optioned RHP Michael Wuertz to Iowa of the PCL. Recalled RHP Roberto Novoa from Iowa.
Team: Cleveland Indians Story: Placed RHP Fernando Cabrera on the 15-day DL. Recalled RHP Fausto Carmona from Buffalo of the IL.
Team: Detroit Tigers Story: Placed INF Dmitri Young on the 15-day DL. Called up OF Alexis Gomez from Toledo of the IL.
Team: New York Yankees Story: Signed INF Carlos Pena and RHP Jesus Colome to minor league contracts.
Team: Pittsburgh Pirates Story: Placed 1B Sean Casey on the 15-day DL. Purchased the contract of INF-OF Mike Edwards from Indianapolis of the IL. Transferred RHP Kip Wells from the 15- to the 60-day DL.
Team: Toronto Blue Jays Story: Activated RHP A.J. Burnett from the 15-day DL.
Team: Washington Nationals Story: Placed RHP Ryan Drese on the 15-day DL. Purchased the contract of RHP Saul Rivera from New Orleans of the PCL.
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/7417-regex-help/#findComment-27394
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.