Jump to content

Need help pulling remote contents


kevin87
Go to solution Solved by Ch0cu3r,

Recommended Posts

Hi everyone,

 

I need some help pulling data from a remote site.  Currently I am using the following code which works and pulls all of the data. The next step is where I am a little lost.

$str = file_get_contents("http://www.airnav.com/airport/KARR");

I would like to only pull the following data from the remote site.

<A name="ops"></A><H3>Airport Operations</H3>
<TABLE cellpadding=0 cellspacing=0 border=0>
<TR><TD nowrap valign=top align=right>Airport use: </TD><TD valign=top>Open to the public</TD></TR>
<TR><TD nowrap align=right>Activation date: </TD><TD>04/1966</TD></TR>
<TR><TD nowrap valign=top align=right>Sectional chart: </TD><TD valign=top><A href="/sectionals">CHICAGO</A></TD></TR>
<TR><TD nowrap align=right>Control tower: </TD><TD>yes</TD></TR>

Can anyone help me out with this?

 

Thanks,

Kevin

Link to comment
Share on other sites

Find what you are looking for using regex

$html = file_get_contents("http://www.airnav.com/airport/KARR");
preg_match('~<a name="ops"></a>.+</h3>(.*?)</table>~is', $html, $matches);
$targetData = trim($matches[1]);

echo $targetData;

If you dont want the html included then apply strip_tags to $targetData;

Edited by Ch0cu3r
Link to comment
Share on other sites

Thanks a lot for the response. I ran this code and had a little trouble, but I think it is getting closer. Maybe I can understand it if there is less data. What if I just wanted to grab this string and print it?

 

<A name="ops"></A><H3>Airport Operations</H3>

Link to comment
Share on other sites

  • Solution

I have issue with my regex pattern, change it to

preg_match('~<a name="ops"></a>(.*?)</table>~is', $html, $matches);

$targetDate will contain


<H3>Airport Operations</H3>
<TABLE cellpadding=0 cellspacing=0 border=0>
<TR><TD nowrap valign=top align=right>Airport use: </TD><TD valign=top>Open to the public</TD></TR>
<TR><TD nowrap align=right>Activation date: </TD><TD>04/1966</TD></TR>
<TR><TD nowrap valign=top align=right>Sectional chart: </TD><TD valign=top><A href="/sectionals">CHICAGO</A></TD></TR>
<TR><TD nowrap align=right>Control tower: </TD><TD>yes</TD></TR>
<TR><TD valign=top align=right>ARTCC: </TD><TD valign=top>CHICAGO CENTER</TD></TR>
<TR><TD valign=top align=right>FSS: </TD><TD valign=top>KANKAKEE FLIGHT SERVICE STATION</TD></TR>
<TR><TD nowrap valign=top align=right>NOTAMs facility: </TD><TD valign=top>ARR (NOTAM-D service available)</TD></TR>
<TR><TD align=right>Attendance: </TD><TD>0600-2400</TD></TR>
<TR><TD nowrap align=right>Wind indicator: </TD><TD>lighted</TD></TR>
<TR><TD nowrap align=right>Segmented circle: </TD><TD>no</TD></TR>
<TR><TD valign=top align=right>Lights: </TD><TD valign=top>WHEN ATCT CLSD HIRL RYS 15/33 &  09/27 & MIRL RY 18/36 PRESET LOW INTST; TO INCR INTST & ACTVT MALSR RYS 09, 33; REIL RYS 18;36,15,33 & 27, AND TWY LGTS - CTAF.</TD></TR>
<TR><TD valign=top align=right>Beacon: </TD><TD valign=top>white-green (lighted land airport)<BR>Operates sunset to sunrise.</TD></TR>
Edited by Ch0cu3r
Link to comment
Share on other sites

Also a second question. Is there a way to print only line 75 to 100 when using 

If you want specific lines, then you could do

$html = file("airport.html");

$targetData ='';
// start at line 75 and loop till line 100
for($i = 74; $i <= 99; $i++)
{
	$targetData .= $html[$i]; // add html to variable
}

echo $targetData; // echo html
Edited by Ch0cu3r
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.