Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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 - Fatal编程技术网

PHP函数不会重复

PHP函数不会重复,php,Php,我试图找出为什么下面的整个代码在运行所有函数后只生成一个结果,而不是生成多个结果 代码应该从基于文本的搜索中获取单个结果,然后检查用户服务器上的每个文件并找到该字符串,然后输出包含该搜索字符串的每个文件 代码只生成一个结果,而不是输出包含输入字符串的所有文件 我曾经有过这样的工作,但是代码是根据之前在这个网站上的一个问题修改的,现在工作不完全正确 <?php if (!isset($_REQUEST['query'])) { //Ask for query here :)

我试图找出为什么下面的整个代码在运行所有函数后只生成一个结果,而不是生成多个结果

代码应该从基于文本的搜索中获取单个结果,然后检查用户服务器上的每个文件并找到该字符串,然后输出包含该搜索字符串的每个文件

代码只生成一个结果,而不是输出包含输入字符串的所有文件

我曾经有过这样的工作,但是代码是根据之前在这个网站上的一个问题修改的,现在工作不完全正确

<?php

if (!isset($_REQUEST['query'])) 
{ 
    //Ask for query here :)      
    //echo "<p style=\"color:darkgray; font-family:arial\">Sorry. Please enter a search term.</p>"; 
    exit; 
} 

$query = isset($_REQUEST['query']) ? $_REQUEST['query'] : ''; 


if (empty($query)) 
{ 
    echo "<p style=\"color:#575757; font-family:arial\">We are unable to process your request becuase you didn't enter a search term. Please try again.</p>"; 
    exit; 
} 


$filesFound = find_files('.'); 

if (!$filesFound) 
{ 
    echo "<p style=\"color:#575757; font-family:arial\">No files contained the search, \"$query\". Please try another search.</p>"; 
} 


function find_files($seed) 
{ 
    if (!is_dir($seed)) return false; 
    $found = false; 
    $dirs = array($seed); 

    while (NULL !== ($dir = array_pop($dirs))) 
    { 
        if ($dh = opendir($dir)) 
        { 
            while (false !== ($file = readdir($dh))) 
            { 
                if ($file == '.' || $file == '..') continue; 
                $path = $dir . '/' . $file; 
                if (is_dir($path)) 
                { 
                    $dirs[] = $path; 
                } 
                else 
                { 
                    if (preg_match('/^.*\.(php[\d]?|js|txt)$/i', $path)) 
                    { 
                        if (!$found) 
                        { 
                            $found = check_files($path); 
                        } 
                    } 
                } 
            } 
            closedir($dh); 
        } 
    } 
    return $found; 
} 

function check_files($this_file) 
{ 
    $query = $_REQUEST['query']; 

    $str_to_find = $query; 


    if (($content = file_get_contents($this_file)) === false) 
    { 
        echo("<p style=\"color:#575757; font-family:arial\">Could not check $this_file</p>\n"); 
        return false; 
    } 
    else 
    { 
        if (stristr($content, $str_to_find)) 
        { 
            echo("<p style=\"color:#575757; font-family:arial\">$this_file -> contains $str_to_find</p>\n"); 
            return true; 
        } 
    } 
} 

?>

此if子句只允许找到一个文件。换成

if (check_files($path))
    $found = true;
此if子句只允许找到一个文件。换成

if (check_files($path))
    $found = true;

好的,弗加斯……谢谢你。那么我该如何更改它以显示其根目录下多个目录的结果呢?很好,Furgas。非常感谢你的帮助。你的答案就是我完成Wordpress插件所需要的答案。现在尝试并提交给Wordpress!!好的,弗加斯……谢谢你。那么我该如何更改它以显示其根目录下多个目录的结果呢?很好,Furgas。非常感谢你的帮助。你的答案就是我完成Wordpress插件所需要的答案。现在尝试并提交给Wordpress!!