2009-09-29 38 views
1

我有一個相當簡單的問題PHP語法不工作

誰能告訴我這是爲什麼不上一個新行顯示每個變量,以及除了 的<br>

$curtime = gmdate("d/m/Y H:i:s"); 
    //capture the PayPal returned information as order remarks 
$oremarks = 
"##$curtime##<br>". 
"PayPal Transaction Information...\n". 
"Txn Id: ".$ppInfo["txn_id"]."\n". 
"Txn Type: ".$ppInfo["txn_type"]."\n". 
"Item Number: ".$ppInfo["item_number"]."\n". 
"Payment Date: ".$ppInfo["payment_date"]."\n". 
"Payment Type: ".$ppInfo["payment_type"]."\n". 
"Payment Status: ".$ppInfo["payment_status"]."\n". 
"Currency: ".$ppInfo["mc_currency"]."\n". 
"Payment Gross: ".$ppInfo["payment_gross"]."\n". 
"Payment Fee: ".$ppInfo["payment_fee"]."\n". 
"Payer Email: ".$ppInfo["payer_email"]."\n". 
"Payer Id: ".$ppInfo["payer_id"]."\n". 
"Payer Name: ".$ppInfo["first_name"]." ".$ppInfo["last_name"]."\n". 
"Payer Status: ".$ppInfo["payer_status"]."\n". 
"Country: ".$ppInfo["residence_country"]."\n". 
"Business: ".$ppInfo["business"]."\n". 
"Receiver Email: ".$ppInfo["receiver_email"]."\n". 
"Receiver Id: ".$ppInfo["receiver_id"]."\n"; 

//Update database using $orderno, set status to Paid 
//Send confirmation email to buyer and notification email to merchant 
//Redirect to thankyou page 
echo $oremarks; 

感謝理查德

回答

1

大概是因爲你是從PHP生成的HTML源代碼,而不是純文本。

在HTML中,新行被視爲與任何其他空白一樣。您需要一個<br>元素或者是display: block(或類似的)來觸發換行符。

1

在html中,換行符永遠不會排隊。你必須把<br>放在你的源代碼中。

請注意,PHP也可以獨立於HTTP服務器作爲命令行工具工作,並不一定會生成HTML。

因此,如果您在Web服務器中將內容類型設置爲純文本而不是html,則在文件的開頭使用header("Content-type: plain/text");,文本將按照您的預期進行排列。

+0

好的,謝謝大家,我diddnt不知道關於html輸出 – Richard 2009-09-29 14:40:01

3

因爲您在瀏覽器窗口中輸出結果,請嘗試使用"<br />"而不是「\ n」。

0

\ n只在來源中顯示換行符。
是HTML的「換行」字符。

1

嘗試交替爲您的數組值的雙引號,使用單引號代替

$curtime = gmdate("d/m/Y H:i:s"); 
    //capture the PayPal returned information as order remarks 
$oremarks = 
"##$curtime##<br>". 
"PayPal Transaction Information...\n". 
"Txn Id: ".$ppInfo['txn_id']."\n". 
"Txn Type: ".$ppInfo['txn_type']."\n". 
"Item Number: ".$ppInfo['item_number']."\n". 
"Payment Date: ".$ppInfo['payment_date']."\n". 
"Payment Type: ".$ppInfo['payment_type']."\n". 
"Payment Status: ".$ppInfo['payment_status']."\n". 
"Currency: ".$ppInfo['mc_currency']."\n". 
"Payment Gross: ".$ppInfo['payment_gross']."\n". 
"Payment Fee: ".$ppInfo['payment_fee']."\n". 
"Payer Email: ".$ppInfo['payer_email']."\n". 
"Payer Id: ".$ppInfo['payer_id']."\n". 
"Payer Name: ".$ppInfo['first_name']." ".$ppInfo['last_name']."\n". 
"Payer Status: ".$ppInfo['payer_status']."\n". 
"Country: ".$ppInfo['residence_country']."\n". 
"Business: ".$ppInfo['business']."\n". 
"Receiver Email: ".$ppInfo['receiver_email']."\n". 
"Receiver Id: ".$ppInfo['receiver_id']."\n"; 

//Update database using $orderno, set status to Paid 
//Send confirmation email to buyer and notification email to merchant 
//Redirect to thankyou page 
echo $oremarks; 

但我會建議使用HEREDOC,而不是連接字符串

$curtime = gmdate("d/m/Y H:i:s"); 
     //capture the PayPal returned information as order remarks 
    $oremarks =<<<OREMARKS 
##$curtime## 
PayPal Transaction Information... 
Txn Id: $ppInfo['txn_id'] 
Txn Type: $ppInfo['txn_type'] 
Item Number: $ppInfo['item_number'] 
Payment Date: $ppInfo['payment_date'] 
Payment Type: $ppInfo['payment_type'] 
Payment Status: $ppInfo['payment_status'] 
Currency: $ppInfo['mc_currency'] 
Payment Gross: $ppInfo['payment_gross'] 
Payment Fee: $ppInfo['payment_fee'] 
Payer Email: $ppInfo['payer_email'] 
Payer Id: $ppInfo['payer_id'] 
Payer Name: $ppInfo['first_name'] $ppInfo['last_name'] 
Payer Status: $ppInfo['payer_status'] 
Country: $ppInfo['residence_country'] 
Business: $ppInfo['business'] 
Receiver Email: $ppInfo['receiver_email'] 
Receiver Id: $ppInfo['receiver_id'] 
OREMARKS; 

    //Update database using $orderno, set status to Paid 
    //Send confirmation email to buyer and notification email to merchant 
    //Redirect to thankyou page 
    echo $oremarks; 
+0

感謝heredoc語法,這將在未來派上用場 – Richard 2009-10-20 10:09:42

0

的「\ n」是隻需在html代碼中創建一個新行,它不會創建一個可見的新行。您需要使用html來使新行可見。您可以使用的HTML休息<br>也可以使每行一個段落<p> your text... </p>或者你可以使用一個列表:

<ul> 
    <li> your text... </li> 
    <li> next item... </li> 
    <li> more stuff.. </li> 
</ul> 
0

嘗試把在以下幾點:

<?php 
echo "<pre>"; 
. 
. 
. 
?>