Jump to content

clarencek

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Everything posted by clarencek

  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!
  16. Thanks for the rapid response.  Isn't the Internet wonderful?
  17. Hi, I'm a bit new at php and need help with some string manipulation. I'm getting a variable out of my database with this call:  $t_city = $row['t_city'];  Basically $t_city = "New York".  What I want to do is manipulate the string such that it becomes "New+York". I was trying this, but it doesn't seem to work: $t_city = str_replace(\' \',\'+\',$t_city); What am I doing wrong?
  18. [!--quoteo(post=388972:date=Jun 28 2006, 02:37 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 28 2006, 02:37 PM) [snapback]388972[/snapback][/div][div class=\'quotemain\'][!--quotec--] You said you had access to your php.ini? You just open it up and find the line that says [i]allow_url_fopen = Off[/i] to [i]allow_url_fopen = On[/i] It may not state Off it might be set to 0 instead. Additonally you might be able to use the following in your script: [code]// enable url fopen ini_set("allow_url_fopen", "On");[/code] [/quote] So, the code in the script did not work. I don't have access to the php.ini file, but they allow you to make a custom one. In my custom one, can I just have that one line stating "allow_url_fopen = On"? Or does it need to include a bunch of other stuff?
  19. Hi, I'm using a Yahoo API to get geo data with the following php: <?php error_reporting(E_ALL); // output=php means that the request will return serialized PHP $request = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=infofornyc&street=701+First+Street&city=Sunnyvale&state=CA&output=php'; $response = file_get_contents($request); if ($response === false) { die('Request failed'); } $phpobj = unserialize($response); echo '<pre>'; print_r($phpobj); echo '</pre>'; ?> The output of this is as below: Array ( [ResultSet] => Array ( [Result] => Array ( [precision] => address [warning] => The exact location could not be found, here is the closest match: 701 First Ave, Sunnyvale, 94089 [Latitude] => 37.416384 [Longitude] => -122.024853 [Address] => 701 FIRST AVE [City] => SUNNYVALE [State] => [Zip] => 94089-1019 [Country] => US ) ) ) This is probably a simple newbie question, but how do I access just the Latitude number? I want to grab that number and stick it in a mySQL database. I thought it would be something like: echo $phpobj[ResultSet[Result[1]]]; How do I access that variable.
  20. [!--quoteo(post=388931:date=Jun 28 2006, 01:09 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 28 2006, 01:09 PM) [snapback]388931[/snapback][/div][div class=\'quotemain\'][!--quotec--] Try a relative path instead if the file is on your server. or see if you can turn on [b]allow_url_fopen[/b] setting in the php.ini. [/quote] So, being the newbie, I'm not even sure how to turn on the allow_url_fopen in the php.ini. Can someone walk me through this please?
  21. Hi, I host with GoDaddy.com and am receiving an error when trying to use the file_get_contents() function: "Warning: file_get_contents(): URL file-access is disabled in the server configuration" I know with GoDaddy, I can set up a custome php.ini file. Is that where I can make the changes to enable file-access? I am a newbie so have no idea how to do this. Any help is greatly appreciated. Thanks.
×
×
  • 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.