【问题标题】:Purging & Removing Part of URL清除和删除部分 URL
【发布时间】:2013-10-07 02:41:01
【问题描述】:

我正在创建一个 vine 视频共享网站。

我遇到了一些问题。我的 og:image:secure_url 无法正确获取,因为 url 显示如下..

https://v.cdn.vine.co/v/thumbs/2013/04/30/5D309EAF-962F-41E1-8F22-41E4AA50FFB7-967-00000195162F03BD_1.0.7.mp4.jpg?versionId=JQ9YuwCeBry1sGZpZU40Z3wc_VF_PMb1

所以 facebook 在调试时给了我这个错误..

   Object at URL 'http://vinesandstuff.com/' of type 'article' is invalid because the given value '' for property 'og:image:secure_url' could not be parsed as type 'url'.

如何在后端设置..

og:image:secure_url 设置,注意脚本使用 Smarty 代码。

<meta property="og:image:secure_url" content="{php} echo vine_pic($this->_tpl_vars['p']['youtube_key']);{/php}" />

以及从 twitter 抓取 og:image 的脚本..

function vine_pic( $id )
{

$vine = file_get_contents("http://vine.co/v/{$id}");
                                        preg_match('/property="og:image" content="(.*?)"/', $vine, $matches);

return ($matches[1]) ? $matches[1] : false;

}

我需要什么帮助

正在删除 url ?versionId=JQ9YuwCeBry1sGZpZU40Z3wc_VF_PMb1 的此结尾部分

我查看了其他 stackoverflow 问题,但我不太了解它应该如何设置为语法。有人可以帮助我吗?非常感谢。

【问题讨论】:

    标签: php smarty vine


    【解决方案1】:

    使用 parse_urlhttp_build_query 将该 URL 拆开,然后在没有 versionID 的情况下将其重新组合在一起

    我从未使用过 smarty 标签,所以我不确定那部分。在php中我会做这样的事情:(未经测试)

    $pic_link=vine_pic($this->_tpl_vars['p']['youtube_key']);
    $parsed=parse_url($pic_link);
    $pic_vars=parse_str($parsed['query']);
    unset($pic_vars['$parsed']);
    $new_query=http_build_query($pic_vars);
    $new_pic_link=$parsed['scheme'].$parsed['host'].$parsed['path']'?'.$new_query;
    //if the above is missing a slash, change the dot to .'/'.
    ?>
    <meta property="og:image:secure_url" content="<?php echo $new_pic_link; ?>">
    

    【讨论】:

    • hmm 但是我应该如何设置语法呢?我只有一个月的时间进入 php 并且一次又一次地学习,所以你不得不原谅我.. 我也试过这个,但我不知道我的后端脚本的哪一部分应该放在哪里.. $link = substr($linkraw, 0, strrpos($linkraw, "."))
    • 你好 TecBrat,我用你的代码试过了,不像 &lt;?php ?&gt; 它被称为 {php}{/php} 但是我确实尝试了你的更新和 content= 输出 ?
    猜你喜欢
    • 1970-01-01
    • 2012-02-26
    • 2021-06-23
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多