Jump to content

make url active


flemingmike

Recommended Posts

hi all,

 

i cannot seem to figure out how to make the url active when i parse it from a string.  any ideas?

 

<?php   
//this array contains sports and their URLs 
$sports = array( 
"NHL" => "http://sports.espn.go.com/nhl/bottomline/scores",
"URL" => "http://sports.espn.go.com/nhl/bottomline/scores"); 
$results = array(); 
foreach ( $sports as $sport => $url ) { 
  //get the page pointed to by $url 
    $page = file_get_contents($url); 
    //grab all variables out of the page 
    preg_match_all("/&([^=]+)=([^&]+)/", urldecode($page), $foo); 
    //loop through all the variables on the page 
    foreach ( $foo[1] as $key => $value ) { 
      //debug output, you can delete this next line 
      //echo "{$value} = {$foo[2][$key]}\t<br />\n"; 
    //this chain of IF/elseif statements is used to determine which pattern to use 
    //to strip out the correct data, since each sport seems to have its own format 
    //for the variables you'd "want" 
      if ( $sport == 'URL' && preg_match("/s_url\d+/", $value) ) { 
       $results[$sport][] = $foo[2][$key]; 
      } 
    elseif ( $sport == "NHL" && preg_match("/s_left\d+/", $value) ) { 
      $results[$sport][] = $foo[2][$key]; 
    }  
    }   
     
} 

//calculate the sport with the most number of rows 
$limit = 0; 
foreach ( $results as $countMe ) { 
  $limit = max($limit, count($countMe)); 
} 

//spit out the table with the right headers 

echo '<img src="nhl.jpg">';
echo "<table border=1 cellpadding=2><tr><th>" . implode("</th><th>", array_keys($sports)) . "</th></tr>"; 
//loop until you reach the max number of rows, printing out all the table rows you want 
for ( $p = 0; $p < $limit; $p++ ) { 
  echo "<tr align=center>"; 
  foreach ( array_keys($sports) as $sport ) { 
    echo "<td>{$results[$sport][$p]}</td>"; 
  } 
  echo "</tr>"; 
} 
//kill the table 
echo "</table>";     

Link to comment
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.