|
|
|
|
![]() ![]() |
Jan 29 2006, 02:23 AM
Post
#1
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,074 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
I am just learning to code some php and have been fighting this problem that should be so simple, but I am having a real problem with it.
Since I am new to the language, and I haven't done much coding lately, I am inserting 'echo' or 'print' statements into the script I am writing so that the script can tell me whether the contents of a couple of variables are in fact being altered during the script. This tells me whether the script is functioning as I think it should at various times, so I can 'de-bug' the code. BUT, I can't seem to get the 'new line' or 'carriage return' escaped properly. I have been using "\n\r" inside single quotes, double quotes, no quotes, a variable name, and still the output is all in one long string which is not easy to read. I even went to phpbuilder.com and snagged a line from their tutorial and can't get the output to print onto new lines for me in order to make the debugging simpler. I'm thinking the correct code should be: CODE echo "this should be \n\n a new line here \n\rand here, too"; but it all comes out without the line feeds. As I said above, I've tried single quotes, double quotes, variables, no qoutes, concatenations, but they all fail... Example output: a long string all run together: QUOTE flat_file_data.txtThis spans multiple lines. The newlines will be output as well.this should be a new line here and here, tooThis spans multiple lines. The newlines will be output as well.No forced echo... we have a handle/home/jlhaslip/public_html/testsidebar/flat_file_data.txtartfold @ artfold %line here/n/rartfold1 @ artfold1 %1line here/n/rartfold2 @ artfold2 %2line here/n/rartfold3 @ artfold3 %3line here/n/r @ %4line here/n/r Any suggestions? This post has been edited by jlhaslip: Jan 29 2006, 02:28 AM |
|
|
|
Jan 29 2006, 02:32 AM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 372 Joined: 14-October 04 Member No.: 1,736 |
What you need is the <br> HTML tag before each newline character. HTML doesn't accept newlines. So, for example (using the example you used):
CODE echo "this should be <br>\n<br>\n a new line here <br>\n and here, too"; You won't need to do the carriage return for a new line in the page. |
|
|
|
Jan 29 2006, 03:05 AM
Post
#3
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,074 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
QUOTE flat_file_data.txt No forced echo... we have a handle /home/jlhaslip/public_html/testsidebar/flat_file_data.txtartfold artfold line here/n/rartfold1 artfold1 1line here/n/rartfold2 artfold2 2line here/n/rartfold3 artfold3 3line here/n/r 4line here/n/r Thanks... topic being closed. |
|
|
|
Jun 5 2008, 12:39 PM
Post
#4
|
|
|
Hail Caesar! ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
How to display test in saperate line
Php \"newline\" Character Printing Fails Respected Sir, I have writen a php file as below. But I got mail in one line. What is a coading to desplay all variable in new(saperate) line. Pls help me. $msg = $_REQUEST['name']; $msg .= $_REQUEST['dob']; $msg .= $_REQUEST['organization']; $msg .= $_REQUEST['designation']; $msg .= $_REQUEST['department']; $msg .= $_REQUEST['email']; $msg .= $_REQUEST['mobile']; $msg .= $_REQUEST['tel']; $msg .= $_REQUEST['fax']; $msg .= $_REQUEST['name1']; $msg .= $_REQUEST['email1']; $msg .= $_REQUEST['name2']; $msg .= $_REQUEST['email2']; $msg .= $_REQUEST['name3']; $msg .= $_REQUEST['email3']; $msg .= $_REQUEST['name4']; $msg .= $_REQUEST['email4']; $message = str_replace("\and", "<br/>", $msg); $headers = "From:$name"; Mail( "info@automationpltd.Com", "Feedback Form", $message, $headers); Regards, Ashish Panchal -question by Ashish Panchal |
|
|
|
Jul 8 2008, 08:09 AM
Post
#5
|
|
|
Hail Caesar! ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 5,876 Joined: 21-September 07 Member No.: 50,369 |
new line character appears correctly in browser but it does not print in file.
Php \"newline\" Character Printing Fails In the above code the new line character appears correctly in the browser but when I try to replace the word text which is written in the file certificate.Rtf with the string $text, new line characters have not any effect and the tag <br> appears in the file new_certificate.Rtf as text. File certificate.Rtf is a simple rtf file contains only the word text. Echo "this should be <br>\and<br>\and a new line here <br>\and and here, too"; $text="this should be <br>\and<br>\and a new line here <br>\and and here, too"; $filename = 'certificate.Rtf'; $filename2 = 'new_certificate.Rtf'; // open our template file $fp = fopen ( $filename, 'are' ); if (!$fp) { echo "Error in file opening!"; echo "<br>"; } //generate the headers to help a browser choose the correct application header( 'Content-Disposition: filename=cert.Rtf'); header( 'Content-type: msword' ); //read our template into a variable $output = fread( $fp, filesize( $filename ) ); // replace the place holders in the template with our data $output = str_replace( 'text', $text, $output ); if (file_exists($filename2)) { $fp2 = fopen($filename2, 'are+'); } else { $fp2 = fopen($filename2, 'x+'); } if (!$fp2) { echo "Error in file2 opening!"; echo "<br>"; } fwrite($fp2, $output); fclose($fp); fclose ( $fp2 ); Thank you in advance! -question by Marios Vlachos |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 11th October 2008 - 09:30 PM |