2012-01-11 63 views
0

求助,謝謝大家的反饋!非常感激。簡單的PHP語法問題

如果任何人都可以幫助一個簡單的語法問題,我在這裏將不勝感激。我仍然處於php的學習階段,似乎無法弄清楚這一點。在下面的代碼中,我將數組和定義分配給它,但是當我試圖回顯信息時,它不起作用。

$arr_features=array("PasswordProtect"); 

    $arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: "echo ($_POST['PasswordProtect']);""); 

所以基本上「你的密碼是:」部分不起作用,有什麼想法爲什麼?提前致謝。

+3

「It does not work」is * never * a good error description。而是描述出了什麼問題,你得到了什麼錯誤信息等。 – 2012-01-11 16:10:58

+0

就是這樣,我沒有收到任何錯誤信息或任何東西;而不是帶我到確認頁面,通常沒有回聲部分,它只是給我一個空白的白色屏幕。 – NewB 2012-01-11 16:15:11

+0

[啓用錯誤報告](http://kb.siteground.com/article/How_to_enable_error_reporting_in_a_PHP_script.html),以便您可以查看出了什麼問題。它可能不會總是給你解決問題的方法,但它會告訴你它打破了哪條線 – 2012-01-11 16:16:25

回答

2

既然你正在學習PHP:

echo()將輸出一個字符串來呈現的HTML。 如果你想在另一個字符串的末尾附加一個字符串(生成或不),你需要使用連接運算符(在PHP中爲.)(是的,一個點)連接它們。

在您的例子,它變成了: $arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: " . $_POST['PasswordProtect']);

1

$arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: " . $_POST['PasswordProtect']);

1

因爲你嘗試在字符串中嵌入的聲明。而是正確的語法

$arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: {$_POST['PasswordProtect']}"); 
1
$arr_features=array("PasswordProtect"); 

$arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: ".$_POST['PasswordProtect']); 

這是正確的代碼

1

要輸出的變量在一個字符串,你需要使用.串接:

$arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: " . $_POST['PasswordProtect']); 

或大括號{}

$arr_FeaturesDescriptions = array("Password Protection: Password Protection will be enabled, requiring participants to enter a password in order to access the event. Your password is: {$_POST['PasswordProtect']}"); 
1

您應該過濾來自$ _POST的數據,然後在您的代碼中使用它。由於使用的是雙引號,你可以很容易地插入變量這種方式,因爲在PHP中一個雙引號字符串內評估的變量:

$passwordprotect = validate_input($_POST['PasswordProtect']); 
$arr_features=array("PasswordProtect"); 
$arr_FeaturesDescriptions = array("Password Protection: ... Your password is: $passwordprotect"); 

但你真的不應該不分顯示明文密碼。

1

而不是echo(),你應該使用string concatenation。您可以將$_POST['PasswordProtect']用花括號({})包裹在帶引號的字符串中,或​​者使用'。'將該值附加到字符串的末尾。運營商。

以下是php.net上string data type documentation的鏈接,詳細說明了您可以在PHP中處理字符串的不同方式。