【问题标题】:Php get_meta_tags doesn't getting result (help)php get_meta_tags 没有得到结果(帮助)
【发布时间】:2020-09-15 15:59:27
【问题描述】:

我想传递用户输入的 youtube url 并在结果中获取关键字或标签。

但我不知道出了什么问题。

当我点击提交按钮时没有任何反应

  <?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"/>

提前致谢

【问题讨论】:

  • 将 get_meta_tags('yt') 更改为 get_meta_tags($yt) (传递变量而不是文字文本).. 你也不需要 htmlentities() 因为你没有将值输出到客户端.对于未来,始终包含对您的问题的完整详细说明。只是说 “它不起作用” 并不能真正告诉我们有关您的问题的任何信息。
  • @Magnus Eriksson 让我更新并得到它
  • @Magnus Eriksson 更新代码后没有任何反应
  • 我没有在我的建议中将变量放在单引号内。这将最终传递文字字符串$yt,而不是变量的值。您需要传递实际变量:get_meta_tags($yt)。我也不明白你为什么在这里使用htmlentities()。当您输出(如echo)值时,这用于将HTML 转义为实体。它在这里根本没有用处。

标签: php html


【解决方案1】:

这是一个工作示例

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

您的代码中有 3 个小错误:

  1. 您的提交名称是Submit 您正在检查submit
  2. 您的提交输入位于&lt;form&gt; 之外
  3. 您使用$yt 有点错误。如果您想将变量作为参数发送给函数,则无需使用 '$yt' 包装它。

这是我提交此表单后得到的结果

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)

【讨论】:

  • 非常感谢您的指正和详细解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-17
相关资源
最近更新 更多