Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:07:56+00:00 2026-06-04T15:07:56+00:00

I copy the source of a webpage into a text document and I am

  • 0

I copy the source of a webpage into a text document and I am having trouble getting two data points from the file; the latitude and longitude.

The php file I have to make and scan the document is this:

<?php

$ch = curl_init("http://www.marinetraffic.com/ais/shipdetails.aspx?MMSI=258245000");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);

header('Content-Type: text/plain');

$myFile = "example_homepage.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 9251);
fclose($fh);
echo $theData;

?> 

The gps is buried in text that looks like this (from the file example_homepage.txt):

<img style="border: 1px solid #aaa" src="flags/NO.gif" />
<br/>
<b>Call Sign:</b>LAJW
<br/>
<b>IMO:</b>9386380,
<b>MMSI:</b>258245000
<br/>
<hr/>
<h2>Last Position Received</h2>
<b>Area:</b>North Sea
<br/>
<b>Latitude / Longitude:</b>
<a href='default.aspx?mmsi=258245000&centerx=5.311533&centery=60.39997&zoom=10&type_color=9'>60.39997˚ / 5.311533˚ (Map)</a>
<br/>
<b>Currently in Port:</b>
<a href='default.aspx?centerx=5.32245&centery=60.39085&zoom=14'>BERGEN</a>
<br/>
<b>Last Known Port:</b>
</b>
<a href='default.aspx?centerx=5.32245&centery=60.39085&zoom=14'>BERGEN</a>
<br/>
<b>Info Received:</b>0d 0h 20min ago
<br/>
<table>
    <tr>
        <td>&nbsp;
            <img src="shipicons/magenta0.png" />
        </td>
        <td>
            <a href='default.aspx?mmsi=258245000&centerx=5.311533&centery=60.39997&zoom=10&type_color=9'><b>Current Vessel's Track</b></a>
        </td>
    </tr>
    <tr>
        <td>
            <img src="windicons/w05_330.png" />
        </td>
        <td>
            <b>Wind:</b>5 knots, 327&deg;, 13&deg;C</td>
    </tr>
</table>
<a href='datasheet.aspx?datasource=ITINERARIES&MMSI=258245000'><b>Itineraries History</b></a>
<br/>
<hr/>
<h2>Voyage Related Info (Last Received)</h2>
<b>Draught:</b>6.8 m
<br/>
<b>Destination:</b>BERGEN HAVN
<br/>
<b>ETA:</b>2012-05-22 18:00
<br/>
<b>Info Received:</b>2012-05-23 18:43 (

The two numbers I want are:

latitude: 60.39085
longitude: 5.32245

I am not so experienced with this kind of thing. Maybe there is a better way. Please let me know.

EDIT: FYI with the last three lines of code, I am able to get the first 9251 characters in the text file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:07:58+00:00Added an answer on June 4, 2026 at 3:07 pm

    This is what I did to get the result I wanted: (prints out *-70.19347 42.02112 *)

    <?php
    //goes though and copies the web page to a text file
    $ch = curl_init("http://photos.marinetraffic.com/ais/lightdetails.aspx?light_id=1000019773");
    $fp = fopen("example_homepage.txt", "w");
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    
    //prevents some parsing of the html document
    header('Content-Type: text/plain');
    
    //opens text file and reads contents to a string
    $myFile = "example_homepage.txt";
    $fh = fopen($myFile, 'r');
    $theData = fread($fh,12000);
    fclose($fh);
    
    //finds the location of the beginning of the GPS data
    $pos = strrpos($theData, "&centerx=");
    if ($pos === false) { 
        // note: three equal signs
        echo "not found";
    }
    
    //cuts out that string and finds position for x and y components
    $subtract = 12000-$pos-36;
    $rest = substr($theData, $pos, -$subtract);
    $lat = substr($rest, 9, -17);
    $lonpos = strrpos($rest, "&centery=")+9;
    $lon = substr($rest, $lonpos);
    
    //turns the values into floats
    $lat = floatval($lat);
    $lon = floatval($lon);
    
    //echo $rest;
    echo $lat;
    echo " ";
    echo $lon;
    
    ?> 
    

    Hope this helps someone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to copy the text file through vb6 code. Having Source filename like clock.fin,
When inserting copy into an HTML document I get from sources such as word
I am using File.Copy(source, dest, true) to copy a file from local to remote
I've got a source code file that started as a copy of some sample
This is my code to copy files in a list from source to destination.
I saw How to hide html source & disable right click and text copy?
I am using BeautifulSoup to scrape data from a webpage. I want to compare
I have text files with one source and two destination path..I'm sending those to
When i use the command : FILE.copy(source path , destination path) it's perform the
When I copy source code to a word document or email, it would be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.