flemingmike Posted May 26, 2010 Share Posted May 26, 2010 2 questions... in my code, where would i put my style, ie. background colors, etc. second question, how would i make the second column (url) an actual link? here is my code: <?php //this array contains sports and their URLs $sports = array( "MLB" => "http://sports.espn.go.com/mlb/bottomline/scores", "URL" => "http://sports.espn.go.com/mlb/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 == "MLB" && 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="mlb.gif">'; 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>"; thanks, mike Link to comment https://forums.phpfreaks.com/topic/203022-bg-color-and-link-should-be-no-brainer/ Share on other sites More sharing options...
mrMarcus Posted May 26, 2010 Share Posted May 26, 2010 you would put your style(s) wherever you need them. if you need your table to have a blue background, set your style in the table tag, and so on. second question: if you don't know how to create HTML links, perhaps PHP is a little over your head. Link to comment https://forums.phpfreaks.com/topic/203022-bg-color-and-link-should-be-no-brainer/#findComment-1063840 Share on other sites More sharing options...
flemingmike Posted May 26, 2010 Author Share Posted May 26, 2010 i know how to make links, but the url column is being parsed from a url string and then placed in the table. im not sure how to make it a link rather than just text. Link to comment https://forums.phpfreaks.com/topic/203022-bg-color-and-link-should-be-no-brainer/#findComment-1063842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.