gpt4 book ai didi

php - 从包含的文件调用函数?

转载 作者:可可西里 更新时间:2023-11-01 00:16:55 24 4
gpt4 key购买 nike

我正在制作一个 PHP 脚本来为我做一些事情,所以我不必在我的网站文档中一遍又一遍地输入所有代码。

这是我的做法:

// MyFunc.php
<?php
function DoStuff()
{
$var = 'something';
return $var;
}
?>


// index.php
<html>
<head></head>
<body>
Hi, I am currently doing <?php include "MyFunc.php"; echo DoStuff(); ?>, pretty cool, right?
</body>
</html>

但是,我的函数似乎没有被调用。我做错了什么吗?

这是我的完整来源

//splashgen.php
<?php

$refid = $_GET['ref'];
$output = 'Company';

function GetSponsor()
{

if($refid!='')
{
$dbhost = "localhost";
$dbuser = "myuser";
$dbpass = "mypass";

$dbname = "mydb";

$sqlselect = "SELECT * FROM egbusiness_members WHERE loginid='$refid';";

$con = mysql_connect($dbhost,$dbuser,$dbpass) or die('Unable to connect to Database Server!');
mysql_select_db($dbname) or die('Could Not Select Database!');

$refid = stripslashes($refid);
$refid = mysql_real_escape_string($refid);

$result = mysql_query($sqlselect);

while ($row = mysql_fetch_array($result))
{
$output = $row['name_f']." ".$row['name_l']." (".$refid.")";
}
mysql_close($con);
}
return $output;

}


?>

/////////

// index.php

...

<font style="font-size:19px" color="#0093C4" face="Calibri"><b>
This page was brought to you by: <?php $_GET['ref']; include "../splashgen.php"; echo GetSponsor(); ?>
</b></font></div>
...

最佳答案

<body>
Hi, I am currently doing <?php include "MyFunc.php"; echo DoStuff(); ?>, pretty cool, right?
</body>

并确保您的 php 文件应以 <?php 开头

关于php - 从包含的文件调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5869031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com