Jump to content

clarencek

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.infofornyc.com

Profile Information

  • Gender
    Not Telling

clarencek's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Good stuff!  Thanks.  This pretty much gets me where I want.  I still need to tweak my final html page, but that stuff will be easier for me to do myself. Thanks a ton.
  2. Hmm... I don't get it.  I'm still getting the same blank array even after cutting and pasting your exact code.  I guess this works on your end?  Not sure why I'm not getting anything.
  3. Can you show me your complete code? Here is what I have [code]error_reporting(E_ALL); $url = 'http://LocalCopyOftheHTMLPage'; $page = file_get_contents($url); if (preg_match_all('/<tr>\n<td><a.+?>(.+?)<\/a>.*?\n.*?<a.+?>(.+?)<\/a>.*?\n.*?<td>(.+?)<\/td>.*?\n.*?<a.+?>(.+?)<\/a>, <a.+?>(\d+)/i', $page, $matches)); echo '<pre>' . print_r($matches,true) . '</pre>'[/code] But the output I get on html page is such: [code]Array (     [0] => Array         (         )     [1] => Array         (         )     [2] => Array         (         )     [3] => Array         (         )     [4] => Array         (         )     [5] => Array         (         ) )[/code] Results are blank.  Am I doing something wrong here?  I believe I'm using the exact code that you typed up.
  4. Hmm...I'm not sure I'm getting this to work.  I have put my code below with my comments and questions in the //Comments. ------------------------------ [code]error_reporting(E_ALL); $url = 'http://en.wikipedia.org/wiki/Broadway_theatre'; $page = file_get_contents($url);[/code] //This part below grabs just the table html, excluding the first <table> and the last </table> and stores it in $links[0][1] [code]if (preg_match_all('/<table.class="wikitable">.+?<\/tr>(.+?)<\/table>/si', $page, $links, PREG_SET_ORDER));[/code] // Then I put in your code [code]if (preg_match_all('/<tr>\n<td><a.+?>(.+?)<\/a>.*?\n.*?<a.+?>(.+?)<\/a>.*?\n.*?<td>(.+?)<\/td>.*?\n.*?<a.+?>(.+?)<\/a>, <a.+?>(\d+)/i', $links[0][1], $matches));[/code] // But when I print it out, I get a blank array.  Am I doing something wrong with your snippet? [code]echo '<pre>' . print_r($matches,true) . '</pre>'[/code] //Also, I was trying to keep date and year in one field although I don't know if that matters here.
  5. Crayon (great explanations by the way): Yes, that's exactly what I'm doing.  Here's a copy of the page that I've been practicing on: http://www.infofornyc.com/maptest/wiki.html And the code that I used for the first part: [code]$url = 'http://www.infofornyc.com/maptest/wiki.html'; $page = file_get_contents($url); if (preg_match_all('/<table.class="wikitable">.+?<\/tr>(.+?)<\/table>/si', $page, $links, PREG_SET_ORDER)) $cells = preg_replace('/<a.href.+?">|<\/a>|<\/?i>/i', '', $links[0][1]); if (preg_match_all('/<td>(.+?)<\/td>/si', $cells, $sql, PREG_SET_ORDER)) for($i = 0; $i < count($sql); $i++){ echo $sql[$i][1];   } [/code] I imagine I'm not using the functions very well or correctly.  If you can explain a better way to do it, that would be greatly appreciated.  Thanks again.
  6. To Crayon Violent, No, my array is not so clean unfortunately. It's the case that $sql[0][1]= theatername1 $sql[1][1]= show1 $sql[2][1]= address1 $sql[3][1]= date1 $sql[4][1]= theatername2 $sql[5][1]= show2.....and so on. This is obviously not good, but I was unsure how else to build the array aside from the code I posted at the time stamp 1:44:37 am. How can I get a clean array structure as you suggest? And if I do get there, can you explain your code a little bit?  What does the $key => $val mean or do?  I can interpret the rest okay, but this part is a key step which I'm not sure what it's doing.  Thanks.
  7. Maybe it is my noobieness that I am not constructing a clean array.  It was set up as such by crawling a html page: [code] if (preg_match_all('/<table.class="theater_list">.+?<\/tr>(.+?)<\/table>/si', $page, $links, PREG_SET_ORDER)) $cells = preg_replace('/<a.href.+?">|<\/a>|<\/?i>/i', '', $links[0][1]); if (preg_match_all('/<td>(.+?)<\/td>/si', $cells, $sql, PREG_SET_ORDER)) for($i = 0; $i < count($sql); $i++){ echo $sql[$i][1];   } [/code] Was there a better way to get the better array structure suggested? Thanks.
  8. Also, I don't get any errors reporting.  Nothing at all appears in the browser window, and when I look at the database, nothing has changed.  Here is my latest code: [code] for($i = 0; $i < count($sql); $i+4){ mysql_query("Update theater SET t_name = '$sql[$i][1]', t_address = '$sql[$i+1][1]', t_show = '$sql[$i+2][1]', t_updated = '$sql[$i+3][1]' WHERE t_name = $sql[i][1]"); } [/code]
  9. Sorry, again, without the bad formatting. [code] Array (     [0] => Array         (             [0] => <td>Ambassador Theatre</td>             [1] => Ambassador Theatre         )     [1] => Array         (             [0] => <td>Chicago</td>             [1] => Chicago         )     [2] => Array         (             [0] => <td>219 West 49th Street</td>             [1] => 219 West 49th Street         )     [3] => Array         (             [0] => <td>Nov. 14, 1996</td>             [1] => Nov. 14, 1996         )     [4] => Array         (             [0] => <td>American Airlines Theatre</td>             [1] => American Airlines Theatre         )     [5] => Array         (             [0] => <td>The Pajama Game</td>             [1] => The Pajama Game         )     [6] => Array         (             [0] => <td>227 West 42nd Street</td>             [1] => 227 West 42nd Street         )     [7] => Array         (             [0] => <td>Feb. 23, 2006</td>             [1] => Feb. 23, 2006         )     [8] => Array         (             [0] => <td>Brooks Atkinson Theatre</td>             [1] => Brooks Atkinson Theatre         )     [9] => Array         (             [0] => <td>The Times they are a Changin'</td>             [1] => The Times they are a Changin'         )     [10] => Array         (             [0] => <td>256 West 47th Street</td>             [1] => 256 West 47th Street         )     [11] => Array         (             [0] => <td>Oct. 27, 2005</td>             [1] => Oct. 27, 2005         ) [/code]
  10. Here are the first three "lines". Array (     [0] => Array         (             [0] => Ambassador Theatre             [1] => Ambassador Theatre         )     [1] => Array         (             [0] => Chicago             [1] => Chicago         )     [2] => Array         (             [0] => 219 West 49th Street             [1] => 219 West 49th Street         )     [3] => Array         (             [0] => Nov. 14, 1996             [1] => Nov. 14, 1996         )     [4] => Array         (             [0] => American Airlines Theatre             [1] => American Airlines Theatre         )     [5] => Array         (             [0] => The Pajama Game             [1] => The Pajama Game         )     [6] => Array         (             [0] => 227 West 42nd Street             [1] => 227 West 42nd Street         )     [7] => Array         (             [0] => Feb. 23, 2006             [1] => Feb. 23, 2006         )     [8] => Array         (             [0] => Brooks Atkinson Theatre             [1] => Brooks Atkinson Theatre         )     [9] => Array         (             [0] => The Times they are a Changin'             [1] => The Times they are a Changin'         )     [10] => Array         (             [0] => 256 West 47th Street             [1] => 256 West 47th Street         )     [11] => Array         (             [0] => Oct. 27, 2005             [1] => Oct. 27, 2005         )
  11. Hi, I have an array of date set up $sql. Basically, $sql[0] is a theater name $sql[1] is an address $sql[2] is a show $sql[3] is a date. then it starts over again with $sql[4] is the next theater name, etc.... I am trying to update my database called 'theater' which already has the theater names in the t_name column with the following code: //Set up connection to database $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); for($i = 0; $i < count($sql); $i+4){ mysql_query("Update theater SET t_name = $sql[$i][1] WHERE t_name = $sql[i][1]"); mysql_query("Update theater SET t_address = $sql[$i+1][1] WHERE t_name = $sql[i][1]"); mysql_query("Update theater SET t_show = $sql[$i+2][1] WHERE t_name = $sql[i][1]"); mysql_query("Update theater SET t_updated = $sql[$i+3][1] WHERE t_name = $sql[i][1]"); } For some reason it is not working.  Any reason why? Thanks, CK
  12. Hi, I'm trying to grab a table from html using a php function preg_match_all, but it doesn't seem to work.  Is the following correct? $url = 'http://somehtmlpage.com/blah.html'; $page = file_get_contents($url); if (preg_match_all('/<table>(.+?)<\/table>/gi', $page, $links, PREG_SET_ORDER))   for($i = 0; $i < count($links); $i++){   print_r($links[$i]);   echo "<br />";   } Thanks.
  13. Hi, I'm fairly new to php but am learning quite a bit. I am trying to grab some information from a web page: http://en.wikipedia.org/wiki/Broadway_theatre.  What I want to get is just the table information by storing the theater, the show, the address, and when it opened. Is it possible to do this via php and regular expression? This is what I have so far: <?php error_reporting(0); $url = 'http://en.wikipedia.org/wiki/Broadway_theatre'; $page = file_get_contents($url); if (preg_match_all('/<td>.+?title=".+?">(.+?)<\/a>/im', $page, $links, PREG_SET_ORDER))   for($i = 0; $i < count($links); $i++){     print_r($links[$i]);     echo " ";   } ?> The problem with it is that it picks up everything that starts with <td> includes title and ends in [/url], not just the theater name.  AS for how to pick up the address and opening date by itself, I have no idea how to separate out since they are enclosed in simple <td> </td> tags.  Ultimately I want to take these variables and stick it in the database.  I know how to stick it in the database.  The challenge is getting all the variables. Thanks for any help, Clarence
  14. Hi, I'm fairly new to php but am learning quite a bit. I am trying to grab some information from a web page: http://en.wikipedia.org/wiki/Broadway_theatre.  What I want to get is just the table information by storing the theater, the show, the address, and when it opened. Is it possible to do this via php and regular expression? This is what I have so far: <?php error_reporting(0); $url = 'http://en.wikipedia.org/wiki/Broadway_theatre'; $page = file_get_contents($url); if (preg_match_all('/<td>.+?title=".+?">(.+?)<\/a>/im', $page, $links, PREG_SET_ORDER))   for($i = 0; $i < count($links); $i++){   print_r($links[$i]);   echo "<br />";   } ?> The problem with it is that it picks up everything that starts with <td> includes title and ends in </a>, not just the theater name.  AS for how to pick up the address and opening date by itself, I have no idea how to separate out since they are enclosed in simple <td> </td> tags.  Ultimately I want to take these variables and stick it in the database.  I know how to stick it in the database.  The challenge is getting all the variables. Thanks for any help, Clarence
  15. hahaha...i hear ya.  there's no reason i should be staying up till 4 AM two nights in a row.  i don't think i'll pull a 3rd night.  time for me to go to bed!
×
×
  • 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.