代码之家  ›  专栏  ›  技术社区  ›  hitek

通过php传递多个值

  •  0
  • hitek  · 技术社区  · 17 年前

    这是密码

    <php?  
    $id1 =1;
    $id2 = "module 1 loaded";
    echo "$var1=$id1","$var2=$id2";
    ?>
    

    我知道这不是正确的方法,我怎么能把这两个变量传给flash呢?

    6 回复  |  直到 16 年前
        1
  •  6
  •   Peter Bailey    17 年前
    <?php
    
    echo http_build_query( array(
         'var1' => 1
        ,'var2' => 'module 1 loaded'
    ));
    
        2
  •  2
  •   fuentesjr    17 年前

    PaulDixon的代码截图是您在PHP方面需要的。这是闪光部分:

    myVars = new LoadVars(); 
    myVars.load("http://localhost/foo.php");
    
    myVars.onLoad = function (success) {
         if (success) {
            for( var attr in this ) {
                trace (" key " + attr + " = " + this[attr]); 
            }
        } else {
            trace ("LoadVars Error"); 
        }
    }
    

    注意,您将希望用应用程序需要的任何内容替换循环逻辑。

        3
  •  2
  •   Paul Dixon    17 年前

    如果要创建一个脚本,该脚本输出可以加载的数据 LoadVariables LoadVars 你需要这样的东西

    //set up your values 
    $vars=array();
    $vars['foo']='bar';
    $vars['xyz']='123';
    
    //output     
    header ("Content-Type: application/x-www-urlformencoded");
    $sep="";
    foreach($vars as $name=>$val)
    {
        echo $sep.$name."=".urlencode($val);
        $sep="&";
    }
    

    如果您的PHP版本支持它, http_build_query 使这更容易:

    $vars=array();
    $vars['foo']='bar';
    $vars['xyz']='123';
    
    header ("Content-Type: application/x-www-urlformencoded");
    echo http_build_query($vars);
    
        4
  •  1
  •   cOle2    17 年前

    它不应该只是一个查询字符串的形式:

    echo $var1.'='.$id1.'&'.$var2.'='.$id2;
    

    确保键和值已进行了URLENCODED。

        5
  •  0
  •   sth    16 年前

    闪存代码:

    btn.onPress = function(){
    
       testLoadVars = new LoadVars();
    
       testLoadVars.onLoad = function(success){
    
          if(success){
             trace(testLoadVars.var1);
             trace(testLoadVars.var2);
          }
          else
             trace("error");
       }
       testLoadVars.sendAndLoad("http://localhost/filename.php?uniqueID=" +  getTimer(),testLoadVars,"POST");
    
    }
    

    这就是全部。。有什么问题吗??

        6
  •  0
  •   sth    16 年前

    PHP代码:

    <php?  
    $id1 =1;
    $id2 = "module 1 loaded";
    
    print "&var1=$id1";
    print "&var2=$id2";
    
    ?>
    

    我相信这会奏效…

    推荐文章