Skip to content
Advertisement

Php get_meta_tags doesn’t getting result (help)

I want to pass user input youtube url and get keyword or tags in result.

But i don’t know what is wrong.

When i click on submit button nothing happens

  <?php if( isset($_GET['submit']) ){ $yt = htmlentities($_GET['yt']);
 $tags = get_meta_tags('$yt');   
  echo 
$tags['keywords'];     // php documentation ?>

Html

  <input type="text" name="yt" id="yt"  placeholder="https://youtu.be/jhCD4yCcogE" value="" />
 </form>
  <input type="submit" name="Submit"/>

Thanks in advance

Advertisement

Answer

Here is a working example

<form >
    <input type="text" name="yt" id="yt"  placeholder="https://youtu.be/jhCD4yCcogE" value="https://youtu.be/jhCD4yCcogE" />
    <input type="submit" name="submit"/>
</form>
if (isset($_GET['submit']) && $yt = htmlentities($_GET['yt'])) {
    $tags = get_meta_tags($yt);
    var_dump($tags);exit;
}

There are 3 small mistakes in your code:

  1. Your submit name is Submit you are checking submit
  2. Your submit input located outside of <form>
  3. You are using $yt a little bit wrong. You don’t need to wrap it with '$yt' if you want to send a variable as an argument to the function.

Here is what I’m getting now after submitting this form

array (size=22)
  'theme-color' => string '#ff0000' (length=7)
  'title' => string 'Google My Business Website Tutorial | How to Create free website of Google my business 2020' (length=91)
  'description' => string 'Learn how to create google my business website in 5 minutes (complete tutorial). In tutorial will know about description, how to google my business edit with...' (length=160)
  'keywords' => string 'Google My Business Website Tutorial google my business website builder tutorial, free website, google my business, How To Create a Free Website For Google My...' (length=160)
  'twitter:card' => string 'player' (length=6)
  'twitter:site' => string '@youtube' (length=8)
  'twitter:url' => string 'https://www.youtube.com/watch?v=jhCD4yCcogE' (length=43)
  'twitter:title' => string 'Google My Business Website Tutorial | How to Create free website of Google my business 2020' (length=91)
  'twitter:description' => string 'Learn how to create google my business website in 5 minutes (complete tutorial). In tutorial will know about description, how to google my business edit with...' (length=160)
  'twitter:image' => string 'https://i.ytimg.com/vi/jhCD4yCcogE/maxresdefault.jpg' (length=52)
  'twitter:app:name:iphone' => string 'YouTube' (length=7)
  'twitter:app:id:iphone' => string '544007664' (length=9)
  'twitter:app:name:ipad' => string 'YouTube' (length=7)
  'twitter:app:id:ipad' => string '544007664' (length=9)
  'twitter:app:url:iphone' => string 'vnd.youtube://www.youtube.com/watch?v=jhCD4yCcogE&amp;feature=applinks' (length=70)
  'twitter:app:url:ipad' => string 'vnd.youtube://www.youtube.com/watch?v=jhCD4yCcogE&amp;feature=applinks' (length=70)
  'twitter:app:name:googleplay' => string 'YouTube' (length=7)
  'twitter:app:id:googleplay' => string 'com.google.android.youtube' (length=26)
  'twitter:app:url:googleplay' => string 'https://www.youtube.com/watch?v=jhCD4yCcogE' (length=43)
  'twitter:player' => string 'https://www.youtube.com/embed/jhCD4yCcogE' (length=41)
  'twitter:player:width' => string '1280' (length=4)
  'twitter:player:height' => string '720' (length=3)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement