SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist tangledman's Avatar
    Join Date
    Sep 2005
    Location
    Puerto de Mazarron, Murcia, Spain
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XML Array problem

    Hello everyone,

    what does "->" mean?

    i want to extract the items form the XML array can someone please give me a pointer.

    PHP Code:
    <?

    $province_id 
    $_GET['province_id'];

    include 
    "connect.inc.php";

    $query="SELECT municipality_id, municipality_rewrite_name FROM municipality WHERE province_id = '$province_id'";
    $result=mysql_query($query);

    while (
    $array=mysql_fetch_assoc($result)) {

    $municipality_id $array['municipality_id'];

    $geonames_url "http://ws.geonames.org/search?q=".$array['municipality_rewrite_name'];


    //echo "$geonames_url <br>";

    $xml simplexml_load_file($geonames_url);
    foreach (
    $xml->geoname as $o_location){
        
         
            
    $name $o_location['name'];
            
    /*
            $lat = $o_location->lat;
            $lon = $o_location->lng;
            $geo_name_ID = $o_location->geonameId,
            $geo_country = $o_location->countryCode,
            $o_location->countryName,
            $o_location->fcl,
            $o_location->fcode
            */
            
            
    echo "Name is $name";
        
    }


    echo 
    "<hr>";
    }
    ?>
    Many Thanks

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by tangledman View Post
    Hello everyone,

    what does "->" mean?

    i want to extract the items form the XML array can someone please give me a pointer.
    Off Topic:

    "give me a pointer", class!


    echo $o_location->name ;

    ->name is accessing a property using the object notation whereas
    ['name'] is how to access an array value.

    simplexml uses the former.

  3. #3
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    -> is used to refer to an attribute of an object.

    In your example, $xml is not an array but an object, and it has an attribute called geoname. You can use var_dump($xml) or print_r($xml) to see what the $xml variable contains.

    Or simply read the documentation, simplexml_load_file returns a SimpleXMLElement object.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •