Jump to content

Recommended Posts

Hello, 

 

I am look for some assitence on a project I am working on. It has been a couple years since I have done something like this and I know it is easy to do as I have done it before but, I have forgot some of it. 

 

I am trying to parse this feed http://www.spotternetwork.org/data.php and create variables for the lat, lng and name so I can plot them on a Google Map V4. I do not think I am going about this the right way since those are child nodes and I have completed forgot out to use DOM which I think that is what I need to be using. Right now I am just trying to get it parsed and go from there. Also I need the lat lng to coincide with the name.

## Start Configurable data ##

//Set path to data file
$data = "http://www.spotternetwork.org/data.php";

## End Configurable data ##

$xml = simplexml_load_file($data);

//Set initial output to false
$tData = false;
foreach($xml->spotter as $spotter)
{
    $name        = $spotter['name'];
    $lat         = $spotter['lat'];
    $long        = $spotter['lng'];
   
echo $spotter;

Any help would be greatly appreciated. 

 

-Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/301153-simplexml-question/
Share on other sites

Thanks, yeah you are right. I noticed that after the fact. That is where I am stuck is I need to pull just that data but keep it together from each line. My brain is fried at the moment from trying to remember how to use this all over again. 

## Start Configurable data ##

//Set path to data file
$data = "http://www.spotternetwork.org/data.php";

## End Configurable data ##

$xml = simplexml_load_file($data);

//Set initial output to false
foreach($xml->spotter as $spotter)
{
    $name   = $spotter['name'];
    $lat    = $spotter['lat'];
    $long   = $spotter['lng'];
    
);

Link to comment
https://forums.phpfreaks.com/topic/301153-simplexml-question/#findComment-1532810
Share on other sites

<?php
//Set path to data file
$url = "http://www.spotternetwork.org/data.php";

$xml    = simplexml_load_file($url);
$json   = json_encode($xml);
$array  = json_decode($json, TRUE);
$data   = array();
$number = 0;
foreach ($array['spotter'] as $spotter) {
    foreach ($spotter as $att) {
        if (!in_array($data[$number], $data)) {
            $data[$number] = $att;
        }
    }
    $number++;
    
}
echo "<pre>";
print_r($data);
echo "<pre>";
?>

Results:

Array(    [0] => Array        (            [num] => 43892            [ago] => 3237            [report_at] => 2016-05-04 06:15:42            [lat] => 49.8028831            [lng] => -96.9140015            [name] => Francis Lavigne-theriault            [callsign] =>             [phone] => 2048941561            [email] => nzpchasers@hotmail.com            [first] => Francis            [last] => Lavigne-Theriault            [freq] => CB ch.19 or 9            [twitter] => https://twitter.com/NZPChasers            [note] => NZP Chasers            [ss] => 0            [ctv] => 0            [wdt] => 0            [scl] => 0        )    [1] => Array        (            [num] => 381            [ago] => 2956            [report_at] => 2016-05-04 06:20:23            [lat] => 41.7750587            [lng] => -87.7680969            [name] => Adam Lucio            [callsign] =>             [phone] => 7733838985            [email] => t4rip911@comcast.net            [first] => Adam            [last] => Lucio            [freq] =>             [twitter] =>             [note] => facebook.com/tornadochasing            [ss] => 0            [ctv] => 2            [wdt] => 0            [scl] =>         )    [2] => Array        (            [num] => 1000            [ago] => 2713            [report_at] => 2016-05-04 06:24:26            [lat] => 28.7588730            [lng] => -81.3610764            [name] => Rob Dale            [callsign] => N8GSK            [phone] =>             [email] => rdale@skywatch.org            [first] => Rob            [last] => Dale            [freq] => 145.390MHz            [twitter] =>             [note] => Meteorologist            [ss] => 0            [ctv] => 2            [wdt] => 0            [scl] =>         )    [3] => Array        (            [num] => 44433            [ago] => 2510            [report_at] => 2016-05-04 06:27:49            [lat] => 42.4483376            [lng] => -88.2940445            [name] => Jesse Walters            [callsign] =>             [phone] => 8474567064            [email] => JWSevereWeather@gmail.com            [first] => Jesse            [last] => Walters            [freq] =>             [twitter] => JWSevereWeather            [note] =>             [ss] => 0            [ctv] => 2            [wdt] => 0            [scl] => 0        )    [4] => Array        (            [num] => 19525            [ago] => 1464            [report_at] => 2016-05-04 06:45:15            [lat] => 41.8083725            [lng] => -87.7275162            [name] => James Baugh            [callsign] =>             [phone] => 7733153289            [email] => jimmybaugh@hotmail.com            [first] => James            [last] => Baugh            [freq] =>             [twitter] => StormTechChaser            [note] => Trained Spotter            [ss] => 0            [ctv] => 0            [wdt] => 0            [scl] =>         )    [5] => Array        (            [num] => 6296            [ago] => 1154            [report_at] => 2016-05-04 06:50:25            [lat] => 38.8094177            [lng] => -94.7813110            [name] => Brett Cooper            [callsign] =>             [phone] => 9134613339            [email] => brettc@replayirc.com            [first] => Brett            [last] => Cooper            [freq] =>             [twitter] => bctrainers            [note] =>             [ss] => 0            [ctv] => 0            [wdt] => 0            [scl] =>         )    [6] => Array        (            [num] => 32871            [ago] => 86            [report_at] => 2016-05-04 07:08:13            [lat] => 39.5936432            [lng] => -104.9869995            [name] => Troy Tucker            [callsign] =>             [phone] => 7204101679            [email] => tuckertroy65@gmail.com            [first] => troy            [last] => tucker            [freq] =>             [twitter] =>             [note] => awn wether on zello            [ss] => 0            [ctv] => 0            [wdt] => 0            [scl] =>         )    [7] => Array        (            [num] => 7688            [ago] => 76            [report_at] => 2016-05-04 07:08:23            [lat] => 37.5649986            [lng] => -100.8710022            [name] => Brandon Copic            [callsign] =>             [phone] =>             [email] =>             [first] => Brandon            [last] => Copic            [freq] =>             [twitter] => BrandonCopicWx            [note] => www.Facebook.com/BVStormChasing            [ss] => 0            [ctv] => 0            [wdt] => 0            [scl] =>         )    [8] => Array        (            [num] => 12431            [ago] => 76            [report_at] => 2016-05-04 07:08:23            [lat] => 43.2178650            [lng] => -75.4620285            [name] => Craig Larkin            [callsign] => KB2FED            [phone] => 315-520-9645            [email] => kb2fed@gmail.com            [first] => Craig            [last] => Larkin            [freq] => 146.520 or 146.550 simp            [twitter] =>             [note] => EC- Oneida County, NY            [ss] => 0            [ctv] => 2            [wdt] => 0            [scl] =>         )    [9] => Array        (            [num] => 2899            [ago] => 73            [report_at] => 2016-05-04 07:08:26            [lat] => 39.3093491            [lng] => -80.7072754            [name] => Ricky Shreve            [callsign] => KC5RBA            [phone] => 304-933-9522            [email] => KC5RBA@AOL.COM            [first] => Ricky            [last] => Shreve            [freq] => 146.520 PL Tone - 94.8            [twitter] =>             [note] => SKYWARN ID PB6041 West Union FD            [ss] => 0            [ctv] => 0            [wdt] => 0            [scl] =>         ))
Link to comment
https://forums.phpfreaks.com/topic/301153-simplexml-question/#findComment-1532812
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.