Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌自定义搜索可以';行不通_Php_Search - Fatal编程技术网

Php 谷歌自定义搜索可以';行不通

Php 谷歌自定义搜索可以';行不通,php,search,Php,Search,下面是test.html文件代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-hans" xml:lang="zh-hans"> <head> <meta

下面是test.html文件代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-hans" xml:lang="zh-hans">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
    <div class="fr_search">        
        <form action="cse.php"  accept-charset="UTF-8" method="post"
              id="search-theme-form">    
            <input type="text" maxlength="128" name="search_theme_form"
                id="edit-search-theme-form-1" size="15" value=""  class="form-text" />
            <input type="image" name="submit" id="edit-submit"  
                class="form-submit" src="images/search_btn_top.gif" /></div>
        </form>
    </div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>test search</title>
 </head> 
 <body>
     <script src="http://www.google.com/jsapi" type="text/javascript"></script>
     <script type="text/javascript">
  google.load('search', '1', {language : 'en'});
   google.setOnLoadCallback(function()
    {
       var customSearchControl = new google.search.CustomSearchControl   ('011247711644571852159:xe2ytn1hwsa');
       customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
       customSearchControl.draw('cse');
   }, true);
      </script>
      <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css"
            type="text/css" />      
 <?php echo 'test'; ?>
 </body>
</html>

测试
我把生成的代码。这个 我输入的“要搜索的站点”是。当我将生成的代码放入cse.php时。然后将cse.php和test.html放入本地php环境中。当我在搜索文本框中输入文本“php”并单击搜索按钮时。但是在我的搜索结果页面上没有任何结果。我的步骤和代码有什么问题?多谢各位

以下是cse.php文件代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-hans" xml:lang="zh-hans">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
    <div class="fr_search">        
        <form action="cse.php"  accept-charset="UTF-8" method="post"
              id="search-theme-form">    
            <input type="text" maxlength="128" name="search_theme_form"
                id="edit-search-theme-form-1" size="15" value=""  class="form-text" />
            <input type="image" name="submit" id="edit-submit"  
                class="form-submit" src="images/search_btn_top.gif" /></div>
        </form>
    </div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>test search</title>
 </head> 
 <body>
     <script src="http://www.google.com/jsapi" type="text/javascript"></script>
     <script type="text/javascript">
  google.load('search', '1', {language : 'en'});
   google.setOnLoadCallback(function()
    {
       var customSearchControl = new google.search.CustomSearchControl   ('011247711644571852159:xe2ytn1hwsa');
       customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
       customSearchControl.draw('cse');
   }, true);
      </script>
      <link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css"
            type="text/css" />      
 <?php echo 'test'; ?>
 </body>
</html>

测试搜索
load('search','1',{language:'en'});
setOnLoadCallback(函数()
{
var customSearchControl=new google.search.customSearchControl('01124771164571852159:xe2ytn1hwsa');
customSearchControl.setResultSetSize(google.search.search.FILTERED\u CSE\u RESULTSET);
customSearchControl.draw('cse');
},对);

摆脱站点中的http://搜索位。

我不确定从何处开始您的代码,但使用中的新代码片段,您可以将查询字符串传递给
CustomSearchControl
。借用代码后,类似这样的功能应该可以工作:

<div id="cse">Loading&hellip;</div>
<script src="http://www.google.com/jsapi"></script>
<script>

    // Extract user's query from the URL
    function getQuery() {
        var url = '' + window.location;
        var queryStart = url.indexOf('?') + 1;
        if (queryStart > 0) {
            var parts = url.substr(queryStart).split('&');
            for (var i = 0; i < parts.length; i++) {
                if (parts[i].length > 2 && parts[i].substr(0, 2) == 'q=') {
                    return decodeURIComponent(parts[i].split('=')[1].replace(/\+/g, ' '));
                }
            }
        }
        return '';
    }

    google.load('search', '1', {language:'en' });
    google.setOnLoadCallback(function() {
        var cseControl = new google.search.CustomSearchControl('ID_GOES_HERE');
        cseControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
        cseControl.draw('cse');
        // Execute a query based on the query string
        cseControl.execute(getQuery());
    }, true);
</script>

魔法不足。在您尝试插入自己的代码之前,该站点是否在谷歌演示中工作?