Jump to content

Blank Code for PHP


nideba

Recommended Posts

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

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

that will only put line breaks in the cource code not in html that is rendered
you can also echo html if you wanted
echo "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

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

<?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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...