0

Please can someone tell me what I am doing wrong? I am trying to retrieve all the data in the array below in PHP and I am having problems doing this. Here is the example:

<?php

$url = 'http://www.example.com/';

if (!$fp = fopen($url, 'r')) {
    trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}

$meta = stream_get_meta_data($fp);

print_r($meta);

foreach($meta as $key=>$value) {
    echo '<br>'.$value;

}

fclose($fp);

?>

The foreach loop above permit me to loop through and retrieve all the data in the array, but my questions are:

  1. How can I retrieve only the value http of [wrapper_type] and other values independently?
  2. How can I retrieve only one value of [wrapper_data] => Array without retrieving all the values together?
  3. What is the index number or value to access these data?
3
  • Ummm... echo $meta['wrapper_type']; Commented Jan 21, 2016 at 22:15
  • What is the index number or value to access these data? - this questions is unclear. Commented Jan 21, 2016 at 22:17
  • wrapper_data array will be variable as it is based on the headers and is in the order that the headers were received. Commented Jan 21, 2016 at 22:17

3 Answers 3

2

This is pretty basic stuff; you may want to do some reading up on PHP basics before progressing further. Nevertheless...

How can I retrieve only the value http of [wrapper_type] and other values independently?

$type = $meta["wrapper_type"];
echo $type;

How can I retrieve only one value of [wrapper_data] => Array without retrieving all the values together?

$the_fourth_header = $meta["wrapper_data"][4];
echo $the_fourth_header;
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Miken, thanks for taking the time to respond. I appreciate it. I will do as you suggested. Thanks.
I already voted up your response and it says I need to earn a total of 15 reputation before the vote would appear. Thanks once again.
2

How can I retrieve only the value http of [wrapper_type]

Just with $meta['wrapper_data']

How can I retrieve only one value of [wrapper_data]

The same, Array elements can be accessed using the array[key] syntax: $meta['wrapper_data'][0], $meta['wrapper_data'][1], ...

Comments

-1

just use 'wrapper_type' index in your array($meta).

$type = $meta["wrapper_type"];
echo $type;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.