nideba Posted September 1, 2006 Share Posted September 1, 2006 What is the Blank code(simlar to html <br>) for PHP? I think it is not in the tutorial. When I try out all the function in all the chapter, I was surprise to see that all the words was in a row. And how can apply the code to my script? Thank you. Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 1, 2006 Share Posted September 1, 2006 There is no special php linebreak. Everything you echo with php, WILL be echoed. So if you echo like this: echo "something1";echo "something2";echo "something3";echo "something4"; you haven't instructed php to echo a linebreak, so only obvious it won't echo it.You should (could) do it at least like this: echo "\r\nsomething1";echo "\r\nsomething2";echo "\r\nsomething3";echo "\r\nsomething4"; This way every new string will be printed after a new line. Notice: ONE newline. Together "carriage return" (\r) and "newline" (\n) produce one new line. This will cause both plain text editors like notepad and rich text editors like wordpad implement ONE linebreak or newline whatever you call it (a newline, \n, would only produce a newline in notepad, wordpad forces to also use \r, so jus always use both \r and \n) Link to comment Share on other sites More sharing options...
aspnetguy Posted September 1, 2006 Share Posted September 1, 2006 that will only put line breaks in the cource code not in html that is rendered Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 1, 2006 Share Posted September 1, 2006 Then an html <br /> should be appended at the end of each string that represents an html line, but What is the Blank code(simlar to html <br>) for PHP? was the question Link to comment Share on other sites More sharing options...
SFB Posted September 1, 2006 Share Posted September 1, 2006 that will only put line breaks in the cource code not in html that is renderedyou can also echo html if you wantedecho "something1 <br>";echo "something2 <br>";echo "something3 <br>";echo "something4 <br>"; Edit: oops posted at the same time as Dan again Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 1, 2006 Share Posted September 1, 2006 But this "\r\n" is as much important, we don't want a source code that consists of only one line, do we? Of cource there is an html line break. The topic starter already mentioned that didn't he?[*Edit:] Yeah you did, lol Link to comment Share on other sites More sharing options...
nideba Posted September 2, 2006 Author Share Posted September 2, 2006 My script was----------------------------------------------------------------------------<html><body><?php$txt="something";$txt2="Something";echo $txt; echo $txt;echo $txt;echo $txt2;echo $txt2;$d=date("D");if ($d=="Mon") echo "Time to work!"; elseif ($d=="Sun") echo "Resting Day!";else echo "Have a nice day!"; <form action="welcome.php" method="post">Name: <input type="text" name="name" />Age: <input type="text" name="age" /><input type="submit" /></form>?></body></html>-------------------------------------------------------------------------------Can this work?In the example you gave,(echo "\r\nsomething1" how can I apply the \r\ to this part?--------------------------------------------------------------($d=date("D");if ($d=="Mon") echo "Time to work!"; elseif ($d=="Sun") echo "Resting Day!";else echo "Have a nice day!"; <form action="welcome.php" method="post">Name: <input type="text" name="name" />Age: <input type="text" name="age" /><input type="submit" /></form> Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 2, 2006 Share Posted September 2, 2006 <?php$txt="\r\nsomething";$txt2="\r\nSomething";echo $txt, $txt, $txt, $txt2, $txt2;($d=date("D");if ($d=="Mon") echo "\r\nTime to work!"; elseif ($d=="Sun") echo "\r\nResting Day!";else echo "\r\nHave a nice day!"; ?><form action="welcome.php" method="post">Name: <input type="text" name="name" />Age: <input type="text" name="age" /><input type="submit" /></form>Here you are :)Notice the change to echo $txt, $txt, $txt, $txt2, $txt2;, you don't have to repeat the echo instrunctiion every string. Besides, you can include them all in one string, so you can format the betweens Like this:echo "$txt and even more $txt. One more $txt, and then one $txt2. And even one more $txt2.";I hope you understand Link to comment Share on other sites More sharing options...
nideba Posted September 3, 2006 Author Share Posted September 3, 2006 Thanks for helping. I understand the first one, but not the second example for variable. Anyway, it is a great help to me. Link to comment Share on other sites More sharing options...
Jack McKalling Posted September 3, 2006 Share Posted September 3, 2006 Well,I try to explain in the secon example that variables are parsed inside a php string, when the string is double quoted (single quoted doesn't). This way you won't have to echo variables between strings, but just easily inside them. Less characters of code, and much more readable.This is a string how you would do it in javascript: "..." + variable1 + "..." + variable2 + "..."Where PHP is able to do just this:"...$variable1...$variable2..." Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now