簡體   English   中英

簡單的PHP語法問題

[英]simple PHP syntax issues

解決了 ,謝謝大家的反饋! 非常感激。

如果有人可以幫助您解決一個簡單的語法問題,將不勝感激。 我仍處於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']);"");

因此,基本上“您的密碼是:”部分不起作用,為什么有任何想法? 提前致謝。

由於您正在學習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']);

$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']}");
$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']);

那是正確的代碼

要以字符串形式輸出變量,您需要使用. 串聯器:

$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']}");

您應該過濾$ _POST中的數據,然后在代碼中使用它。 因為您使用的是雙引號,所以您可以輕松地以這種方式插入變量,因為PHP中的雙引號字符串將對以下變量進行求值:

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

但是無論如何,您實際上都不應該顯示純文本密碼。

而不是echo() ,應該使用字符串連接 您可以將$_POST['PasswordProtect']用大括號({})括在引號內的字符串中,也可以在值的末尾加上'。'。 操作員。

這是php.net上字符串數據類型文檔的鏈接,詳細介紹了在PHP中處理字符串的不同方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM