2016-09-29 106 views
-1

以下php腳本打印幾個語句和變量!他們打印在同一行上!我想一個接一個地打印它們在不同的行中!我該怎麼做? 例如一日2個發言應打印爲:php單獨行打印語句

在PHP編程的樂趣

我學會了如何在PHP

發表評論,但目前它打印在PHP 編程的樂趣我學會了如何在PHP

?php 

echo "Programming in PHP is fun"; 

//This is the 1st programming 4 tutorial 

/*This tutorial helped me 
to gain a good knowledge in php! */ 

print "I learnt how to comment in PHP"; 


echo "A variable name must start with a letter or an underscore '_' -- not a number"; 

echo "A variable name can only contain alpha-numeric characters, underscores (a-z, A-Z, 0-9, and _)"; 

echo "A variable name should not contain spaces. If a variable name is more than one word, it should beseparated with an underscore or with capitalization "; 

$name= "My name is XXX"; 

$number=25; 

$float_number=10.245; 

$negative_number=-12; 

echo($name); 

echo($number); 

echo($float_number); 

echo($negative_number); 


$age=24; 

$feature =$age; 



echo($feature); 

$x=45; 

$y=12; 

echo($x+$y); 


$myName="My name is 'Lasith'"; 

?> 
+0

使用html'br'標記 –

+0

使用'PHP_EOL'。例如: - echo($ x + $ y).PHP_EOL;' –

+2

對於html,它是'
'。對於文本,它是'\ n'或'\ r \ n',它只能用雙引號,或者像Anant所說的PHP_EOL,它不能在引號內工作。 – aynber

回答

1

如果您迴應他們爲純文本發表評論,添加一個換行符後每個回聲:

echo "\n"; 

如果您迴應他們的HTML(在Web瀏覽器),添加一個HTML <br>標籤之後的每個回聲:

echo "<br>"; 

您還可以使用字符串連接

echo "Programming in PHP is fun" . "\n"; 
echo "Programming in PHP is fun" . "<br>"; 

或添加換行或<br>標記爲字符串

echo "Programming in PHP is fun\n"; 
echo "Programming in PHP is fun<br>";