<?php print "Hello\nWorld"; ?>輸出會(huì)是如下形式:
Hello World
在這個(gè)例子中,我們使用了"\n"來實(shí)現(xiàn)換行,輸出結(jié)果是Hello和World各自占一行顯示。 在實(shí)際的應(yīng)用中,我們可能需要輸出多行的信息,比如輸出一段長(zhǎng)文本。這時(shí)我們需要使用多次的"\n"來實(shí)現(xiàn)多行的換行操作,下面的例子展示了這一點(diǎn):<?php print "There are three things you must never do: \n"; print "\t1. Lie to me. \n"; print "\t2. Steal from me. \n"; print "\t3. Fail me in front of my men. \n"; ?>輸出會(huì)是如下形式:
There are three things you must never do: 1. Lie to me. 2. Steal from me. 3. Fail me in front of my men.
在這個(gè)例子中,我們用了三次的"\n"和一次的"\t"來實(shí)現(xiàn)多行的輸出,并且用"\t"來實(shí)現(xiàn)縮進(jìn)的效果。 除了使用"\n"來實(shí)現(xiàn)換行操作,我們也可以使用HTML的換行標(biāo)簽來實(shí)現(xiàn)換行的效果。比如下面這個(gè)例子:
<?php print "I have a dream that one day this nation will rise up and live out the true meaning of its creed: \n"; print "We hold these truths to be self-evident, that all men are created equal.\n"; print "I have a dream that one day on the red hills of Georgia, the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood. \n"; print "I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice. \n"; ?>輸出會(huì)是如下形式:
I have a dream that one day this nation will rise up and live out the true meaning of its creed:
We hold these truths to be self-evident, that all men are created equal.
I have a dream that one day on the red hills of Georgia, the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood.
I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice.
"標(biāo)簽來實(shí)現(xiàn)換行的效果。 總結(jié)一下,在PHP中,我們可以使用"\n"來實(shí)現(xiàn)換行的效果,并且如果我們需要輸出多行的信息,可以使用多次的"\n"來實(shí)現(xiàn)多行的換行操作,也可以使用HTML的換行標(biāo)簽"\
"來實(shí)現(xiàn)換行。無論使用哪種方式,都可以很好地輸出我們期望的信息。