angel1987 Posted August 18, 2011 Share Posted August 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245098-i-need-some-help-with-displaying-data-from-arrays/ Share on other sites More sharing options...
MasterACE14 Posted August 18, 2011 Share Posted August 18, 2011 <?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 } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245098-i-need-some-help-with-displaying-data-from-arrays/#findComment-1258955 Share on other sites More sharing options...
@ Posted August 18, 2011 Share Posted August 18, 2011 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/245098-i-need-some-help-with-displaying-data-from-arrays/#findComment-1258957 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.