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.

<?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
   }

  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.