使用php编写代码块时,页面上的php $变量将被忽略。解决方案,任何人

时间:2012-02-03 00:09:01

标签: php printf

我试图将一个变量嵌入到我用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="&lt;style&gt;\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;
}
&lt;/style&gt;\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>

1 个答案:

答案 0 :(得分:3)

全局变量无法在函数内部访问,除非您使用全局或通过 $ GLOBALS -array访问它们。