YOUTUBE API搜索功能不能正常工作


YOUTUBE API search function doesnt work properly

我在我的网页上有一个搜索功能,使用youtube api来搜索音乐视频。稍后你可以在同一页面上观看。然而,当我使用api时,当我搜索带有空格的东西时,搜索功能就会起作用。当我对字符串做一些改变并用"/"替换所有的空格时,例如eminem lose yourself变成:eminem/lose/yourself,当你搜索这个时,你得不到正确的结果。这是我正在使用的代码的和平:这是我的代码:

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<p>Search:
<input type="text" name="q" />
<input type="submit" name="submit" value="Search" style="margin-top:-30px"/>
</p>
</form>

然后在php端我有:

if (!isset($_POST['q']) || empty($_POST['q'])) {
        die ('ERROR: Please enter one or more search keywords');
} 
else {  
        $q = $_POST['q'];
    $q = str_replace(' ','/',$q);
        //echo $q;

}$feedURL = "http://gdata.youtube.com/feeds/api/videos/-/{$q}?orderby=viewCount&max-results={$i}";$sxml = simplexml_load_file($feedURL);//从opensearch: namespace获取汇总计数数量= sxml美元——>儿童("http://a9.com/-/spec/opensearchrss/1.0/");$total = $counts->totalResults;$startOffset = $counts->startIndex;$endOffset = ($startOffset-1) + $counts->itemsPerPage;

我尝试了不同的方法使搜索功能工作。我使用这个$q = ereg_replace('[[:space:]]+', '/', trim($q)),这不起作用,然后我开始用"+"替换字符串,这又不能正常工作了。我想看看我怎么能有一个搜索功能,工作良好的空间。

尝试像这样设置查询的格式

https://gdata.youtube.com/feeds/api/videos?
q=football+-soccer
&orderby=published
&start-index=11
&max-results=10
&v=2

API的版本非常重要v=2是最新的稳定版本