【问题标题】:Yourls gets only the first Word for TitleYourls 仅获得标题的第一个单词
【发布时间】:2015-02-26 04:06:36
【问题描述】:

我的代码运行良好,但不知何故 Yourls 只获得了网站标题的第一个字。它不会在第一个 Word 的空格之后转发任何内容。

代码

$Artikel    =   $smarty->get_template_vars('Artikel');
$keyword    =   $Artikel->cArtNr;
$title      =   $Artikel->cName;
$short = file_get_contents(''.$siteurl.'/yourls-api.php?signature='.$signature.'&action=shorturl&url='.$shorturl.'&format='.$format.'&keyword='.$keyword.'&title='.$title.'');

如果标题是“我的第一台计算机”,则只有 “我的” 被设置为标题。是因为我的代码还是你的代码?

【问题讨论】:

    标签: php yourls


    【解决方案1】:

    此问题可能与 URL 字符编码有关。您没有对$title 中的空间进行编码,导致 URI 无效。

    您可以使用urlencode 对查询字符串参数执行此操作,但重构代码以使用http_build_query 可能更容易更好:

    $query = http_build_query(array(
        'signature' => $signature,
        'action' => 'shorturl',
        'url' = $shorturl,
        'format' => $format,
        'keyword' => $keyword,
        'title' => $title
    ));
    file_get_contents($siteurl . '/yourls-api.php?' . $query);
    

    【讨论】:

    • 非常感谢雅各布!好吧,我对所有数组都有问题。因为我只在里面留下了标题而不是它的工作。不知道为什么它们不能一起工作,但你帮了我很多!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    相关资源
    最近更新 更多