从另一个函数中调用函数

时间:2014-09-12 13:41:34

标签: php function

我试图从另一个函数中调用一个函数,并使用返回的变量。

function getUserEmail($clean_useremail){
    // Get the POST var
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $useremail = test_input($_POST["useremail"]);
    }
    // Santize
    $clean_useremail = filter_var($useremail), FILTER_SANITIZE_EMAIL);

    if isset($clean_useremail){
        return $clean_useremail;
        // here is where I want to run createXML() using $clean_useremail
    }else{
        echo 'Error, no email received from form.';
    }
}

function createXML(){
    // create xml
}

通过POST提交表单时,将调用第一个函数getUserEmail()。它应该从表单中获取数据,清理并存储它。

我希望之后运行的函数createXML(),并使用变量$clean_useremail

1 个答案:

答案 0 :(得分:1)

您是否只能在createXML内致电getUserEmail

function getUserEmail($clean_useremail){
  // Get the POST var
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
       $useremail = test_input($_POST["useremail"]);
  }
  // Santize
  $clean_useremail = filter_var($useremail), FILTER_SANITIZE_EMAIL);

  if(isset($clean_useremail)){
      createXML($clean_useremail);
      return $clean_useremail;
      // here is where I want to run createXML() using $clean_useremail
  }else{
      echo 'Error, no email received from form.';
  }
}

function createXML(){
  // create xml
}

在您返回$clean_useremail

之前调用它

并将isset($clean_useremail)放在()

之间