PHP变量传递问题。 PHP 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 既然这么想用 直接用全局变量 函数里用global声明下 好了。 代码如下:<?php include_once("config.php"); echo $textTpl; //无显示 $textTpl是config.php里定义的一个变量 $resultS= a($textTpl); //无显示function a($textTpl) { echo $TextTpl;}?> 不知道你config.php是怎樣寫,我試了一下,是可以拿到的,function a中 echo $TextTpl 改為 $textTpl 就可以了。config.php<?php$textTpl = '123';?>include_once("config.php");echo $textTpl; //123$resultS= a($textTpl); //无显示function a($textTpl){ echo $textTpl; // 這裡改小寫,你之前用大寫了,當然不行}輸出 123123 应该是没问题的。变量当然是区分大小写的。虽然php是弱类型的,不过还没弱化到这个地步。 还需要再提示一下,具体在下面找function a($textTpl) { echo $TextTpl;} 这个是你写错了。碰到这种情况,你可以把你include的文件,直接整成源码放在你页面上头,这样查看就容易了 function a($textTpl) { echo $TextTpl;} 那变量一定在 你另一个函数里,还没用global声明 我写了几个函数,请帮我看下哪里错:文件名:function.php<?php function getJson_obj($url){ $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); $res = curl_exec($ch); curl_close($ch); return json_decode($res,true); } function getAccess_token($APPID,$APPSECRET){ $json_obj = getJson_obj("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET); return $json_obj['access_token']; }function getOauth2_obj($APPID,$APPSECRET,$CODE){ $json_obj = getJson_obj("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$APPID.'&secret='.$APPSECRET."&code=".$CODE."&grant_type=authorization_code"); return $json_obj; }function getOpenID($APPID,$APPSECRET,$CODE){ $json_obj =getOauth2_obj($APPID,$APPSECRET,$CODE); return = $json_obj['openid'];} function getOauth_Access_Token($APPID,$APPSECRET,$CODE){ $json_obj =getOauth2_obj($APPID,$APPSECRET,$CODE); return = $json_obj['access_token'];} ?>我在另一个文件login.php里 include_once("function.php");然后这个login.php打开就报500错误,去掉这个引用就正常,请问我些函数哪里有问题? return = $json_obj['openid']; return = $json_obj['access_token'];多了 =你打开错误显示功能,自己就看到了何必自己跟自己过不去? 关于sql注入的请教 jquery ajax提交中文出现乱码? 奇怪!关于cookie!! 更改PHP.ini的问题 PHP 数组去除重复的问题 看看这段代码还能不能优化,我感觉好烦啊! 一个怪问题:文件名称稍微长了一些,就不能下载 你好,在"价格"这个字段上无论设计成int 型还是设计成float都不能使加入 价格 后达到这样的这样的效果 交友网站的源代码 急 关于URL解码 读取数据库中的数据转JSON串 为什么
<?php include_once("config.php");
echo $textTpl; //无显示 $textTpl是config.php里定义的一个变量
$resultS= a($textTpl); //无显示function a($textTpl)
{
echo $TextTpl;}?>
$textTpl = '123';
?>include_once("config.php");
echo $textTpl; //123
$resultS= a($textTpl); //无显示function a($textTpl){
echo $textTpl; // 這裡改小寫,你之前用大寫了,當然不行
}
輸出 123123
还需要再提示一下,具体在下面找function a($textTpl)
{
echo $TextTpl;}
{
echo $TextTpl;}
文件名:function.php
<?php
function getJson_obj($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
return json_decode($res,true);
} function getAccess_token($APPID,$APPSECRET)
{ $json_obj = getJson_obj("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET);
return $json_obj['access_token'];
}function getOauth2_obj($APPID,$APPSECRET,$CODE)
{ $json_obj = getJson_obj("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$APPID.'&secret='.$APPSECRET."&code=".$CODE."&grant_type=authorization_code");
return $json_obj;
}function getOpenID($APPID,$APPSECRET,$CODE)
{ $json_obj =getOauth2_obj($APPID,$APPSECRET,$CODE);
return = $json_obj['openid'];
}
function getOauth_Access_Token($APPID,$APPSECRET,$CODE)
{ $json_obj =getOauth2_obj($APPID,$APPSECRET,$CODE);
return = $json_obj['access_token'];
} ?>我在另一个文件login.php里 include_once("function.php");
然后这个login.php打开就报500错误,去掉这个引用就正常,请问我些函数哪里有问题?
return = $json_obj['access_token'];
多了 =你打开错误显示功能,自己就看到了
何必自己跟自己过不去?