Require/Include 在 php
Require/Include in php
我需要一些帮助,我有 2 个 php 文件,当我调用某些函数时它告诉我
致命错误:在第 13 行 /home/f77inq/public_html/php/shares.php 中调用未定义的函数 get_contents()
尽管在我调用函数的文件中我输入了 require("name ofmy file");
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>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
adad
<?php
$data = get_contents();
print_contents($data);
?>
</body>
</html>
这是我调用函数的文件。
<?php
require("../../php_include/services.php");
require("../../php_include/query.php");
putenv("ORACLE_HOME=/oracle/product/12.1.0/dbhome_1");
function get_contents() {
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
function print_contents($contents) {
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
</tr>
<?php
foreach ($contents['shares'] as $share) {
print "<tr>";
//****** LINKS TO EVERY
$identifier = urlencode($share['COMPANY']);
print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";
print "</tr>";
}
?>
</table>
<?php
}
require ("shares.php"); //<<<<<<<<<<<<<<<<<<<<<<
?>
正如您在下面看到的,我需要共享 php 文件。
两个文件位于同一个文件夹中
为了测试,我将这段代码放在一个名为 like.php-
的文件中
<?php
function get_contents() {
echo "Got it";
}
require ("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>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
<?php
$data = get_contents();
echo $data;
?>
</body>
</html>
它完美无误。
您显示的错误来自文件 shares.php
,而您 require
的文件是 share.php
。由于您显示的所有代码均有效且肯定有效,因此此错误可能发生在流程的其他地方。
我需要一些帮助,我有 2 个 php 文件,当我调用某些函数时它告诉我
致命错误:在第 13 行 /home/f77inq/public_html/php/shares.php 中调用未定义的函数 get_contents()
尽管在我调用函数的文件中我输入了 require("name ofmy file");
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>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
adad
<?php
$data = get_contents();
print_contents($data);
?>
</body>
</html>
这是我调用函数的文件。
<?php
require("../../php_include/services.php");
require("../../php_include/query.php");
putenv("ORACLE_HOME=/oracle/product/12.1.0/dbhome_1");
function get_contents() {
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
function print_contents($contents) {
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
</tr>
<?php
foreach ($contents['shares'] as $share) {
print "<tr>";
//****** LINKS TO EVERY
$identifier = urlencode($share['COMPANY']);
print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";
print "</tr>";
}
?>
</table>
<?php
}
require ("shares.php"); //<<<<<<<<<<<<<<<<<<<<<<
?>
正如您在下面看到的,我需要共享 php 文件。
两个文件位于同一个文件夹中
为了测试,我将这段代码放在一个名为 like.php-
的文件中<?php
function get_contents() {
echo "Got it";
}
require ("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>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
<?php
$data = get_contents();
echo $data;
?>
</body>
</html>
它完美无误。
您显示的错误来自文件 shares.php
,而您 require
的文件是 share.php
。由于您显示的所有代码均有效且肯定有效,因此此错误可能发生在流程的其他地方。