views:

298

answers:

7

Hello,

I am having a rather simple question

can anyone tell me why this is not displaying each variable on a new line, well except for the <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;

thanks Richard

+6  A: 

Carriage returns have no effect if you're viewing this output as HTML, so try turning them into <br> tags with nl2br...

echo nl2br($oremarks);
Paul Dixon
A: 

Presumably because you are generating HTML source code from PHP, and not plain text.

In HTML, a new line is treated like any other whitespace. You need a <br> element or something that is display: block (or similar) to trigger a line break.

David Dorward
+1  A: 

In html, newlines never go to line. You have to put <br> in your source.

Notice that php can also works independently from http server as a command line utility and does not necessarily generate html.

Thus if you set your content type in web server to plain/text instead of html using header("Content-type: plain/text"); at the beginning of your file your text would go to line as you expected.

kriss
ok, thanks everyone, I diddnt't know about the html output
Richard
+1  A: 

Because you are outputting the result in the browser window, try "<br />" instead of "\n".

code_burgar
A: 

\n only shows a newline in the source.
is the "newline" character for HTML.

CRasco
+1  A: 

Try alternating the Double quotes for your array values, use single quotes instead

$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;

But I would recommend using a HEREDOC instead of concatenating a string

    $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;
Phill Pafford
thanks for the heredoc syntax, that will come in handy in the future
Richard
A: 

The '\n' is just creating a new line in the html code, it is not creating a new line that is visible. You need to use html to get the new line to be visible. You can use the the html break <br> or you can make each line a paragraph <p> your text... </p> or you can use a list:

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