Extract data from an array

1

I have the following code:

if (!$curld = curl_init($dominio)) {
    echo "Could not initialize cURL session.\n";
    exit;
}
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
curl_exec($curld);
echo "<pre>";
print_r(curl_getinfo($curld));
echo "</pre>";

and this gives me something like the following:

Array
(
    [url] => HTTP://google.es/
    [content_type] => text/html; charset=UTF-8
    [http_code] => 301
    [header_size] => 320
    [request_size] => 48
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.061777
    [namelookup_time] => 0.028212
    [connect_time] => 0.029891
    [pretransfer_time] => 0.029907
    [size_upload] => 0
    [size_download] => 218
    [speed_download] => 3528
    [speed_upload] => 0
    [download_content_length] => 218
    [upload_content_length] => 0
    [starttransfer_time] => 0.061749
    [redirect_time] => 0
    [redirect_url] => http://www.google.es/
    [primary_ip] => 216.58.201.131
    [certinfo] => Array
        (
        )

    [primary_port] => 80
    [local_ip] => 185.177.153.145
    [local_port] => 56992
)

I would be interested in storing some data of this array in variables for example:

$size_download = curl_getinfo([size_download ]);

But it does not work for me, I do not know how to do it.
Does anyone help me?

Thanks

    
asked by pablo 22.06.2018 в 18:01
source

2 answers

1

As I checked in the official php documentation , you have an error in the line of $size_download = curl_getinfo([size_download]); , since the correct syntax to get size_download would be something like this:

$size_download = curl_getinfo($curld, CURLINFO_SIZE_DOWNLOAD);
    
answered by 24.06.2018 в 22:08
0

You could declare a variable for curl_exec.

$datos = curl_getinfo(curl_exec($curld));

and get it

$size_download = $datos['size_download'];
    
answered by 22.06.2018 в 18:15