Search code examples
phparraysfor-loopphrets

PHRETS GetObject() returns array, need to extract URL


I'm performing a for loop to iterate through MLS listings. I'm able to get every bit of information I need but I can't seem to figure out how to extract the URL from the array I get.

Here's the array I get from my for loop:

PHRETS\Models\Object Object

(

[content_type:protected] => text/xml
[content_id:protected] => 9577056
[object_id:protected] => 1
[mime_version:protected] => 
[location:protected] => http://cdnparap100.paragonrels.com/ParagonImages/Property/P10/CAT/9577056/0/0/0/42ab28468ab0dfc6fd83dfb39e5dfff7/3/55ec2da6d4a32437d345d0992fae1851/9577056.JPG
[content_description:protected] => 
[content_sub_description:protected] => 
[content:protected] => 


[preferred:protected] => 
[error:protected] => PHRETS\Models\RETSError Object
    (
        [code:protected] => 0
        [message:protected] => 
    )

)

The following is the code I'm using to get that output. I'm just wondering if there's a way to do a trim or something to extract the URL so I can store it.

for ($i = 0; $i <= count($listID); $i++) {

$photo = $rets->GetObject('Property', 'Photo', $mls, '*', 1);

foreach ($photo as $image) {
    echo "<pre>";
    print_r($image);
    echo "<br>";
    echo "</pre>";
}
}

Solution

  • You mean like

    foreach ($photo as $image) {
        echo 'Location: ', $image->getLocation(), '<br>';
    }
    

    ?

    See https://github.com/troydavisson/PHRETS/blob/master/README.md#downloading-media-photos-images-documents-etc

    The method is detailed here ~ https://github.com/troydavisson/PHRETS/blob/master/src/Models/Object.php#L109