【发布时间】:2014-07-02 23:27:07
【问题描述】:
我正在尝试在 HTML 行中使用 require_once 将名为“function.php”的文件中的函数执行到 <?php ?>。
accueil.php(C:\wamp\www\e-commerce\MusicStore\accueil.php):
<?php
require_once('http://localhost/e-commerce/MusicStore/templates/function.php');
?>
<!DOCTYPE html>
<html>
<body>
<?php
get_header();
?>
</body>
....
</html>
和function.php(C:\wamp\www\e-commerce\MusicStore\templates\function.php):
<?php
function get_header()
{
echo "<header class=\"header\">
<div class=\"banniere\">
<a href=\"accueil.php\"><img src=\"http://localhost/e-commerce/MusicStore/img/logo.png\" alt=\"banniere\"/></a>
</div>
</header>";
}
?>
我收到“致命错误:调用未定义函数 get_header()”。
但是如果我把 echo 放在函数之外,它就可以工作了。。这只是在函数中它不起作用。
有人知道如何解决这个问题吗?我正在尝试通过添加 PHP 函数来构建我的 html 页面来清除我的网站。
编辑:双 '{' 是 Stackoverflow 上的一个错误,但不在文件中。
【问题讨论】:
-
从
require_once('http://localhost/e-commerce/MusicStore/templates/function.php');删除http://localhost/做require_once('e-commerce/MusicStore/templates/function.php'); -
谢谢,我试过但没用,所以我试了一下:require_once('./templates/function.php');它有效:) 谢谢!
-
require 需要一个路径(建议使用完整路径)而不是 url
-
删除函数中多余的 {
-
@user225416 请使用 mamdouh alramadan 的解决方案。否则,如果您的文件移动,您总是必须更改路径。
标签: php