Jump to content

I need some help with displaying data from arrays.


angel1987

Recommended Posts

Hello all, i am a newbie in php and i am trying to learn things from internet and this forum. I already did a search and read some things on arrays but i am unable to fix this small script.

 

Here is the script.

 

<?php
    $sourceURL = $link;
    $metaData = get_meta_tags($sourceURL);
while (list($key, $val) = each($metaData))
  {
  echo "$key => $val<br />";
  }
    var_dump($metaData);
?>

 

The above code gets the meta section of the link passed to it.

 

And it displays the results as...

 

title => The Internet Movie Database (IMDb)

description => IMDb: The biggest, best, most award-winning movie site on the planet.

keywords => movies,films,movie database,actors,actresses,directors,hollywood,stars,quotes

application-name => IMDb

msapplication-tooltip => IMDb Web App

msapplication-window => width=1500;height=900

msapplication-task => name=Sign-in;action-uri=/register/login;icon-uri=http://i.media-imdb.com/images/SFff39adb4d259f3c3fd166853a6714a32/favicon.ico

array(7) { ["title"]=> string(34) "The Internet Movie Database (IMDb)" ["description"]=> string(69) "IMDb: The biggest, best, most award-winning movie site on the planet." ["keywords"]=> string(77) "movies,films,movie database,actors,actresses,directors,hollywood,stars,quotes" ["application-name"]=> string(4) "IMDb" ["msapplication-tooltip"]=> string(12) "IMDb Web App" ["msapplication-window"]=> string(21) "width=1500;height=900" ["msapplication-task"]=> string(126) "name=Sign-in;action-uri=/register/login;icon-uri=http://i.media-imdb.com/images/SFff39adb4d259f3c3fd166853a6714a32/favicon.ico" }

 

So instead of all the data showing up above, how can i just display the clean values for keywords, title and description in three different text fields respectively? Please help.

Link to comment
Share on other sites

<?php
    $sourceURL = $link;
    $metaData = get_meta_tags($sourceURL);
while (list($key, $val) = each($metaData))
  {
   if($key == 'keywords') {
    // echo text field for keywords
   } elseif($key == 'title') {
    // echo text field for title
   } elseif($key == 'description') {
    // echo text field for description
   }

  }
?>

Link to comment
Share on other sites

any reason why you would not just do this?

 

<?php
    $sourceURL = $link;
    $metaData = get_meta_tags($sourceURL);
    foreach($metaData as $key => $val) {
     echo "$key => $val<br />";
   }
?>

Link to comment
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.