Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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/4/algorithm/12.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 无法重新声明读取文件\u docx() $searchfor=$\u请求[“搜索]; $connect=mysqli_connect(“本地主机”、“根”、“门户”); $cv=mysqli_query($connect,“从上传的_-cv中选择*); $_Php - Fatal编程技术网

Php 无法重新声明读取文件\u docx() $searchfor=$\u请求[“搜索]; $connect=mysqli_connect(“本地主机”、“根”、“门户”); $cv=mysqli_query($connect,“从上传的_-cv中选择*); $

Php 无法重新声明读取文件\u docx() $searchfor=$\u请求[“搜索]; $connect=mysqli_connect(“本地主机”、“根”、“门户”); $cv=mysqli_query($connect,“从上传的_-cv中选择*); $,php,Php,无法重新声明读取文件\u docx() $searchfor=$\u请求[“搜索]; $connect=mysqli_connect(“本地主机”、“根”、“门户”); $cv=mysqli_query($connect,“从上传的_-cv中选择*); $cvcount=mysqli\u num\u行($cv); 对于($i=1;$i < /代码>请张贴一些我想要的代码,但不知道如何?你在循环中声明函数吗?是的,先生。使用函数在循环中是受欢迎的,很高兴它有帮助。你可以考虑接受答案,以便其他人知道

无法重新声明读取文件\u docx()
$searchfor=$\u请求[“搜索];
$connect=mysqli_connect(“本地主机”、“根”、“门户”);
$cv=mysqli_query($connect,“从上传的_-cv中选择*);
$cvcount=mysqli\u num\u行($cv);
对于($i=1;$i


< /代码>请张贴一些我想要的代码,但不知道如何?你在循环中声明函数吗?是的,先生。使用函数在循环中是受欢迎的,很高兴它有帮助。你可以考虑接受答案,以便其他人知道它被解决了。
$searchfor = $_REQUEST["search"];


$connect = mysqli_connect("localhost", "root", "", "portal");
$cv = mysqli_query($connect, "select * from uploaded_cv");
$cvcount = mysqli_num_rows($cv);
for ($i = 1; $i <= $cvcount; $i++) {

    $cvrow = mysqli_fetch_array($cv);
    $filename = $cvrow["candidatecv"];
    echo $filename;


    function read_file_docx($filename) {

        $striped_content = '';
        $content = '';

        if (!$filename || !file_exists($filename))
            return false;

        $zip = zip_open($filename);

        if (!$zip || is_numeric($zip))
            return false;

        while ($zip_entry = zip_read($zip)) {

            if (zip_entry_open($zip, $zip_entry) == FALSE)
                continue;

            if (zip_entry_name($zip_entry) != "word/document.xml")
                continue;

            $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

            zip_entry_close($zip_entry);
        }// end while

        zip_close($zip);

        //echo $content;
        //echo "<hr>";
        //file_put_contents('1.xml', $content);

        $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
        $content = str_replace('</w:r></w:p>', "\r\n", $content);
        $striped_content = strip_tags($content);

        return $striped_content;
    }

    $file = "resume/$filename"; // or /var/www/html/file.docx

    $content = read_file_docx($file);
    if ($content !== false) {

        $pattern = preg_quote($searchfor, '/');
        $pattern = "/^.*$pattern.*\$/m";


        if (preg_match($pattern . "i", $content, $matches)) {

            echo '<br>';
            echo "Found matches:\n";
            echo implode("\n", $matches);
        } else {
            echo "No matches found";
        }
    } else {
        echo 'Couldn\'t the file. Please check that file.';
    }}
<?php
    $searchfor = $_REQUEST["search"];

    /* Declare the function outside the loop */

    function read_file_docx($filename) {
        $stripped_content = '';
        $content = '';

        if (!$filename || !file_exists($filename)) return false;
        $zip = zip_open($filename);
        if (!$zip || is_numeric($zip)) return false;

        while ($zip_entry = zip_read($zip)) {
            if (zip_entry_open($zip, $zip_entry) == FALSE)  continue;
            if (zip_entry_name($zip_entry) != "word/document.xml") continue;
            $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            zip_entry_close($zip_entry);
        }

        zip_close($zip);

        $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
        $content = str_replace('</w:r></w:p>', "\r\n", $content);
        $stripped_content = strip_tags($content);
        return $stripped_content;
    }


    /* query db */
    $connect = mysqli_connect("localhost", "root", "", "portal");
    $cv = mysqli_query($connect, "select * from uploaded_cv");
    $cvcount = mysqli_num_rows($cv);
    for( $i = 1; $i <= $cvcount; $i++ ) {

        $cvrow = mysqli_fetch_array($cv);
        $filename = $cvrow["candidatecv"];
        echo $filename;

        $file = "resume/$filename"; // or /var/www/html/file.docx

        /* call your function inside the loop */

        $content = read_file_docx($file);
        if ($content !== false) {
            $pattern = preg_quote($searchfor, '/');
            $pattern = "/^.*$pattern.*\$/m";

            if (preg_match($pattern . "i", $content, $matches)) {
                echo '<br>';
                echo "Found matches:\n";
                echo implode("\n", $matches);
            } else {
                echo "No matches found";
            }
        } else {
            echo 'Couldn\'t the file. Please check that file.';
        }
    }
?>