谁能帮我做 require 工作?

Can anyone help me to make require working?

所以我有 2 个 php 文件,一个是调用函数,另一个是实现函数。

在实现我调用的函数的文件中 require("shares.php") - shares.php 是调用函数的文件

问题是,它没有看到函数,所以我检查了函数是否存在,不,它们不存在 ((.

请看这里。

shares.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'> 
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> 
<title>Shares</title> 
</head> 

<body> 
<?php

if (function_exists('get_contents')) 
{ 
    if(function_exists('print_contents'))
    {
        $data = get_contents();
        print_contents($data);
    }
}

else
{
    print("Not Found");
}
?>
</body> 
</html> 

下面是函数的实现。

       if(isset($_GET['share']))
        {
            $conn = db_connect();
            if($_GET["newSorting"] == 1)
            {

                 $shares = get_shareSearch($conn, "company");

            }

            if($_GET["newSorting"] == 2)
            {

                $shares = get_shareSearch($conn, "rate");

            }
            if($_GET["newSorting"] == 3)
            {

                 $shares = get_shareSearch($conn, "issue_date");

            }

            db_disconnect($conn);
            $contents = array('shares' => $shares);
            return $contents;
        }

        else
        {
            $conn = db_connect();
            $shares = get_share($conn);
            db_disconnect($conn);
            $contents = array('shares' => $shares);
            return $contents;
        }

    }

    function print_contents($contents) 
    {

        if(count($contents['shares']) == 0)
        {
            echo "<script type = 'text/javascript'>alert('Sorry but share is not found! Q_Q');</script>";

        }
        else
        {
        ?>    
            <table>
                <tr>
                    <th><a href="share-company-links.php?companySort=true">Company Name</a></th>
                    <th><a href="share-company-links.php?rateSort=true">Rate</a></th>
                    <th><a href="share-company-links.php?issueSort=true">Issue date</a></th>
                </tr>
        <?php

        foreach ($contents['shares'] as $share) 
        {
            print "<tr>";
            $identifier = urlencode($share['COMPANY']);
            print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
            print "<td>{$share['RATE']}</td>";

            $issue_date = $share['ISSUE_DATE'];
            $issue_date = $issue_date === NULL ? "&lt; not available &gt;" : $issue_date;
            print "<td>{$issue_date}</td>";
            print "</tr>";
        }
        ?>
            </table>
        <?php
        }
    }

    require_once("shares.php");

    ?>

结果将是未找到

使用这些函数的文件 (share.php) 应该 require 另一个文件,而不是相反。所以,在股票

<body> 
<?php

require_once('thatotherfile.php');

if (function_exists('get_contents')) 
{ 
    if(function_exists('print_contents'))
    {
        $data = get_contents();
        print_contents($data);
    }
}

会起作用。

您可以在使用函数的文件上使用include("otherfile.php")require("otherfile.php")include_once("otherfile.php")require_once("otherfile.php")并且 NOT 在具有函数 的文件上,即:

<!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'> 
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> 
<title>Shares</title> 
</head> 

<body> 
<?php
include_once("otherfile.php");
//the rest of the code...

http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.require.php
http://php.net/manual/en/function.include-once.php
http://php.net/manual/en/function.require-once.php