我正试图将一个变量嵌入到我用php编写的代码块中的文本区域中,这样它就可以很容易地选择并复制到另一个网站。在生产中,变量将从SESSION变量中提取,但为了让您能够尝试将其粘贴到页面上,我已经硬连接了变量值。
问题是php函数没有拾取变量。我已经在写页面之前就已经存在的SESSION变量中尝试过了——不可以。我还尝试将变量加载到页面上的表单中,并通过$_POST获取它们。。。不行。我在这里做错了什么?
<?php session_start();
$fkey ="46";
$bleft = "0.86543";
$bpos = "tp";
$bcolor = "#eb9494";
$blabel = "CALL US";
echo "fkey: " . $fkey . "<br/>" ;
echo "bleft: " .$bleft . "<br/>" ;
echo "bpos: " .$bpos . "<br/>" ;
echo "bcolor: " .$bcolor . "<br/>" ;
echo "blabel: " .$blabel . "<br/>" ;
$updateGoTo = null;
switch ($thepos) {
case "tp":
$updateGoTo = "slideouttesttopDATA.php";
build_HTMLtp();
break;
case "bt":
$updateGoTo ="slideouttestbtmDATA.php";
build_HTMLbt();
break;
case "lt":
$updateGoTo = "slideouttestltDATA.php";
build_HTMLlt();
break;
case "rt":
$updateGoTo = "slideouttestrtDATA.php";
build_HTMLrt();
break;
}
?>
<html>
<body>
<form action="myform" method="post" enctype="application/x-www-form-urlencoded">
<?php
function build_HTMLtp() {
$myfield="<style>'n";
//style blocks
$myfield.=
"#slideouttop:{
position:absolute;
width:190px;height:187px;
top:-238px;
left:50%%;
}
.bizzopop,.bizzopopbtm{
background:url(http://dev.bizzocall.com/images/bcpopupwtrans.png);
background-repeat:no-repeat;
height:auto;
width:201px;
overflow:visible;
min-height:237px;
}
#clickmetop,#clickmebtm {
float:left;
clear:left;
height:20px;
width:80px;
}
#bcbuttontop,#bcbuttonbtm{
background-color:#000000;
position:relative;
cursor:pointer;
float:left;
clear:left;
left:0;
height:30px;
width:140px;
overflow:hidden;
}
.bcsquarebtntop,.bcsquarebtnbtm{
position:relative;
background-color:#000000;
float:left;
clear:left;
border:#ffFFFF;
width:15px;
height:15px;
border-width:2px;
border-style:solid;
left:6px;
top:5px;
}
.innersquarebtn{
background-color:#ffffff;
width:3px;
height:3px;
margin:auto;
margin-top:6px;
position:relative;
}
.btnlabeltxttop{
cursor:pointer;
display:inline;
overflow:visible;
height:40px;
width:100%%;
text-align:left;
text-indent:0;
left:0px;
position:relative;
float:left;
font-size:17px;
font-weight:bold;
color:#00FFFF;
top:-23px;
margin-left:32px;
}'n";
//special handling for variables
$myfield.=".bizzopop {background-color:" . $bcolor . ";}'n";
$myfield.=".btnlabeltxttop {color:". $bcolor .";}'n";
$myfield.="#slideouttop {
left:". 100*($bleft) ."%%;
display:". $tp .";
}
#clickmetop {
position:relative;
float:left;
clear:left;
height:20px;
width:80px;
z-index:1000;
}
</style>'n'n";
//now the html
$myfield.= "<div id='"slideouttop'">
<div class='"bizzopop'">
</div>
<div id='"clickmetop'">
<div id='"bcbuttontop'">
<div class='"bcsquarebtntop'">
<div class='"innersquarebtn'"></div>
</div>
</div>
<div class='"btnlabeltxttop'">". $blabel ."</div>
</div>
</div>'n'n";
//jquery handlers
$myfield.="<script src=" . "'"http://" . "code.jquery.com/jquery-latest.js'"> </script>'"'n
$(function() {'n
$(''#clickmetop').toggle(function() {'n
$(this).parent().animate({marginTop:''187px''}, {queue:false, duration: 500});'n
}, function() {'n
$(this).parent().animate({marginTop:''0px''}, {queue:false, duration: 500});'n
});'n
});'n
</script>
";
printf ($myfield);
}
?>
<textarea name="myfield" cols="100" rows="30"><?php build_HTMLtp();?>
</textarea>
</form>
全局变量在函数内部不可访问,除非您使用Global或通过$GLOBALS-数组访问它们。