cmattoon Posted May 3, 2010 Share Posted May 3, 2010 Hey all, I'm brand new to PHP/SQL, and haven't really gotten into AJAX/JavaScript yet. I have my own server, running PHP and MySQL, and one of the pages brings up information about area hospitals. (Capacity, services, helicopter pad (BOOL), helo pad lat/long, contact information, etc). I have a summary page that shows the most important information, and I would like to receive updates from another site: (hospitalstatus.emsi.org) This website is operated by the region and shows the status (Open, Delay, Closed, etc) for each hospital. Is there a way to collect this data on my own, without having direct access to their server? Some way to scan the HTML and gather data? From "View Source", this is the code. The ID numbers are static, so I could reference them in my code <TD CLASS="alt" NOWRAP> <A HREF="hosp_log.cfm?id=15">AGH - Suburban Campus</A></TD> <TD> <FONT COLOR="GREEN">OPEN </TD> <TD NOWRAP>04/04/07 08:55 </TD> Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/ Share on other sites More sharing options...
Zane Posted May 3, 2010 Share Posted May 3, 2010 By using file_get_contents and a little regex.. this is possible. Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1052214 Share on other sites More sharing options...
cmattoon Posted May 3, 2010 Author Share Posted May 3, 2010 Hm, okay. Is Regex the "really complicated and seldom used because it's so difficult to understand" part of PHP that I skipped over? lol :-\ Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1052634 Share on other sites More sharing options...
Mchl Posted May 3, 2010 Share Posted May 3, 2010 Is Regex the "really complicated and seldom used because it's so difficult to understand" part of PHP that I skipped over? lol :-\ No. It's somewhat complicated and often used part of programming that you skipped over. Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1052682 Share on other sites More sharing options...
cmattoon Posted May 4, 2010 Author Share Posted May 4, 2010 That was a paraphrased quote from the O'Rielly PHP book that I got...lol Someone on another board helped me with this regex, but the problem is I get an "unexpected modifier: ")"" error. I've tried escaping all \\ and have done things like: $regex = "<a....z]*)"; preg_match_all('$regex',$url,$result); // with and without single quotes --Causes "Unexpected T_STRING" error.. New Regex: preg_match_all('<a\b((?!\bid\s*=|>).)*id\s*=(\d+)[^>([^<]*).*?<font\b[^>]*>([a-z]*)',$url,$result); Any ideas?? I had a much simpler regex at one point, but "echo $result[x];" (where X stands for anything I try to put in there) would simply yield "Array" or "Array()", i forget which. I think this is a basic me-not-knowing-PHP issue, but any insight on how I messed up the array would be great too Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1053008 Share on other sites More sharing options...
Mchl Posted May 4, 2010 Share Posted May 4, 2010 preg_ regex pattern must start and end with a delimiter, a character like # / or % thet you don't use in regex itself preg_match_all('#<a\b((?!\bid\s*=|>).)*id\s*=(\d+)[^>([^<]*).*?<font\b[^>]*>([a-z]*)#',$url,$result); Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1053026 Share on other sites More sharing options...
cmattoon Posted May 4, 2010 Author Share Posted May 4, 2010 <?php $url = file_get_contents('http://hospitalstatus.emsi.org'); preg_match_all('#<a\b((?!\bid\s*=|>).)*id\s*=(\d+)[^>([^<]*).*?<font\b[^>]*>([a-z]*)#',$url,$result); echo $result[1]; ?> Returns the following error: Compliation failed: unmatched parentheses at offset 42 on line 3. If its talking about the 42nd character, that's after the second "id" and before the "\s". I don't see any unmatched parentheses? Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1053334 Share on other sites More sharing options...
cmattoon Posted May 5, 2010 Author Share Posted May 5, 2010 Regex Coach is showing the ) before the <font\b part Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1053354 Share on other sites More sharing options...
cags Posted May 5, 2010 Share Posted May 5, 2010 offest 42 means within the pattern, not on that line of code. I'm not entirely sure what your pattern does but the issue I believe is this segment here... (\d+)[^>([^<]*) I think that the first [ is creating a character class meaning that ^>([^ is being considered the contents of the character class. Because the opening bracket is inside the class, the closing bracket doesn't have a 'partner'. Without knowing more it's hard to say if there is a ] missing and it should be [^>]([^<]*), though that seems unlikely, or possibly the [^< is erroneous and it should be (\d+)([^<]*). Quote Link to comment https://forums.phpfreaks.com/topic/200507-i-think-this-is-an-ajax-function/#findComment-1053470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.