Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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_Arrays_Search - Fatal编程技术网

PHP数组搜索不工作

PHP数组搜索不工作,php,arrays,search,Php,Arrays,Search,有谁能帮我解释一下为什么我的array_搜索在我写的这个PHP脚本中不起作用。我已经处理这件事好几天了,无法解决这个问题。我试着将数组搜索移动到所有地方,在循环内,在循环外,我得到了相同的结果。我尝试过搜索不同的数组值,我尝试过包含我自己的函数来搜索我在网上找到的数组。我知道这些值在数组中,因为我已将数组打印到.txt文件中进行调试,现在我不知道下一步要查找什么。有什么想法吗 <?php //this variable tells us how many drupal nodes

有谁能帮我解释一下为什么我的array_搜索在我写的这个PHP脚本中不起作用。我已经处理这件事好几天了,无法解决这个问题。我试着将数组搜索移动到所有地方,在循环内,在循环外,我得到了相同的结果。我尝试过搜索不同的数组值,我尝试过包含我自己的函数来搜索我在网上找到的数组。我知道这些值在数组中,因为我已将数组打印到.txt文件中进行调试,现在我不知道下一步要查找什么。有什么想法吗

   <?php 
//this variable tells us how many drupal nodes or 'paystub pages' we need to create
$nodeCount = 0;
$i = 0;
//needed for creating a drupal node
//for this code to work this script must be run from the root of the drupal installation
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if ($handle = opendir('/var/www/html/pay.*********group.com/upload')) 
{
    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) 
    {
       if ($file != "." && $file != "..") 
       {
            $nodeCount++;
            //We convert the pdf documents into text documents and move put them in the converted folder
            $command = "pdftotext /var/www/html/pay.*********group.com/upload/" . $file . " /var/www/html/pay.*********group.com/upload/converted/" . $file . ".txt";
            //Execute the command above
            $output = exec($command);

        }   
    }       
    closedir($handle);      
}
//subtract two because the folders "array" and "converted" are included because PHP does not differentiate
//between folders and files
$nodeCount = $nodeCount - 2; 
echo "<br />";
echo "<b> $nodeCount pdf files converted </b>";
echo "<br />";
//open the directory
if ($handle2 = opendir('/var/www/html/pay.*********group.com/upload/converted')) 
{

    //check to see if we have reached the last file of our directory, if not stay in loop
    while (false !== ($currentText = readdir($handle2))) 
    {
        //filter out files named . and ..
       if ($currentText != "." && $currentText != "..") 
       {
            //Create a file for array to be printed to
            $createArray = fopen("/var/www/html/pay.*********group.com/upload/arrays/" . $currentText, "w+") or die ("Cannot find file to create array, ID 2");


            //read the file we are on from the loop into the array 
            $currArray = file("/var/www/html/pay.*********group.com/upload/converted/" . $currentText) or die ("Cannot find file to create array, ID 1");


            $ArrSearch = array_search("EMPLOYEE NO. ", $currArray);

            echo "<br />";
            echo "<b> $ArrSearch index found </b>";
            echo "<br />";

            //array_trim($currArray[$i]);           
            //var_dump($currArray[$i]);

            //print array to .txt file for debugging purposes
            $out = print_r($currArray, true);
            fwrite($createArray, $out);
            fclose($createArray);
            $i++;   

        }           
    }
}
?>

我认为你已经改变了你的论点

$ArrSearch = array_search("EMPLOYEE NO. ", $currArray);
应要求,评论已转到回答


@米加:我不确定这是否是问题所在,或者他们是否已经筋疲力尽,在经历了两天的挫折之后,他们只是在尝试任何事情。

我想你已经改变了争论的方向

$ArrSearch = array_search("EMPLOYEE NO. ", $currArray);
应要求,评论已转到回答

@米加:我不确定这是否是问题所在,或者他们是否已经筋疲力尽,在经历了两天的挫折之后,他们只是在尝试任何事情。

array\u search(针头,干草堆)

你不是有点不对劲吗?(在干草堆中搜索针,而不是相反)。

阵列搜索(针,干草堆)

你不是有点不对劲吗?(在干草堆中烧针,而不是相反)。

$idx=($needle,$haystack)

您需要在代码中交换needle和haystack($needle,$haystack)


您需要在代码中交换针线和干草堆我猜您正在搜索包含员工编号的行,例如“员工编号7”等等。如果您使用
array\u search(“EMPLOYEE NO.”,$currray)
它会搜索与完全匹配的行“EMPLOYEE NO.”,因此您不会得到任何点击


如果要搜索以“EMPLOYEE NO.”开头的值,则必须在数组中循环并使用
strpos()
查找匹配项。

我猜您正在搜索包含员工编号的行,例如“EMPLOYEE NO.7”等等。如果您使用
array\u search(“EMPLOYEE NO.”,$currray)
它会搜索与完全匹配的行“EMPLOYEE NO.”,因此您不会得到任何点击



如果要搜索以“员工编号”开头的值,则必须在数组中循环并使用
strpos()
查找匹配项。

什么不起作用?你能找出你正在搜索的内容、文件中的内容和不匹配的内容吗?这将比一大块代码更有效。我认为你的论点是针锋相对<代码>$ArrSearch=array\u search(“员工编号,$currsearch”)@Brad你应该加上这一点,因为答案中包含了解决问题所需的一切。到底什么不起作用?你能找出你正在搜索的内容、文件中的内容和不匹配的内容吗?这将比一大块代码更有效。我认为你的论点是针锋相对<代码>$ArrSearch=array\u search(“员工编号,$currsearch”)@Brad您应该补充一点,作为一个答案,您需要解决您的问题。我纠正了这个问题,数组被打印到正确的.txt文件中,就像它们应该的那样,所以我知道我正在创建一个数组。我还知道我正在搜索的字符串后面有一个空格。是否可以打印$ArrSearch以便我们可以查看正在搜索的内容?然后,如果不明显的话,也许可以指出你想要找到哪个元素?我纠正了这个问题,数组被打印到正确的.txt文件中,就像它们应该的那样,所以我知道我正在创建一个数组。我还知道我正在搜索的字符串后面有一个空格。是否可以打印$ArrSearch以便我们可以查看正在搜索的内容?然后指出你想找到的元素,如果不明显的话?已修复但仍不工作,看一看我原始postFixed中的编辑代码但仍不工作,看一看我原始postFixed中的编辑代码但仍不工作,看一看我原始postFixed中的编辑代码但仍不工作,看一看我原始帖子中编辑的代码,我正在搜索确切的字符串EMPLOYEE NO.因为无论索引EMPLOYEE NO.位于何处,实际的员工编号始终是下一行。我建议您在数组中循环,并用echo“.$row.”打印每一行;要查看您要查找的行的确切措词,甚至可以将正确的行复制粘贴到搜索它的代码中。很可能您缺少确切的措辞。不,我正在搜索确切的字符串EMPLOYEE NO。因为无论索引EMPLOYEE NO.位于何处,实际的员工编号始终是下一行。我建议您在数组中循环,并用echo“.$row.”打印每一行;要查看您要查找的行的确切措词,甚至可以将正确的行复制粘贴到搜索它的代码中。很有可能你遗漏了确切的措辞。