printf中的换行符(\ n)不起作用? [英] Newline (\n) in printf doesn't work?

查看:1048
本文介绍了printf中的换行符(\ n)不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP的新手。


我看到PHP支持C printf函数,我看过例子

就像printf一样(Hello world!\ n);但是换行符\\ n \\ n \\ n
无法正常工作 - 也就是说,它不会生成HTML< br> ;,我会b / b
预期 - 它是什么确实是在html

生成的文本中生成换行符,但由于浏览器忽略了空行,因此对于大多数应用程序来说,这个

功能似乎没用。


>从此产生了两个问题:



1.我误解了什么?


2.将换行符插入PHP

字符串的规定方法是什么? (可能是printf(Hello world!< br>)?


谢谢,

M. McDonnell

解决方案

Michael写道:


我是PHP新手。


我看到PHP支持C printf函数,我看过像

喜欢printf(Hello world!\ n);但是换行了字符\ n

不起作用 - 也就是说,它不会生成一个HTML< br>,我会b
预期 - 它的作用是生成html

生成文本中的换行符,但由于浏览器忽略空白行,因此对于大多数应用程序来说,这个

功能似乎没用。


>>由此产生了两个问题:



1.我误解了什么?


2.将换行符插入PHP

字符串的规定方法是什么? (可能是printf(Hello world!) < br>")?


谢谢,

M. McDonnell



它工作良好。它会生成一个nl字符,就像你要求的那样。

看看你的源代码 - 你会看到换行符。


如果你想要一个HTML< bror xthtml< br />,你需要自己编码

。 PHP不能为您转换。


-

==================
删除x来自我的电子邮件地址

Jerry Stuckle

JDS计算机培训公司
js ******* @ attglobal.net

==================


5月27日晚上8:05,Jerry Stuckle< jstuck ... @ attglobal.netwrote:


Michael写道:


我是PHP的新手。


我看到PHP支持C printf函数,我看过例如

就像printf("你好世界!\ n");但是换行符\\ n \\ n \\ n
无法正常工作 - 也就是说,它不会生成HTML< br> ;,我会b / b
预期 - 它是什么确实是在html

生成的文本中生成换行符,但由于浏览器忽略空白行,因此对于大多数应用程序来说,这个

功能似乎没用。


>由此产生两个问题:


1.我误解了什么?


2.将换行符插入PHP

字符串的规定方法是什么? (可能是printf(Hello world!< br>)?


谢谢,

M 。麦克唐纳



它工作正常。它会生成一个nl字符,就像你要求的那样。

看看你的源代码 - 你我会看到换行符。


如果你想要一个HTML< bror xthtml< br />,你需要对它们进行编码

你自己.PHP不会为你转换。


-

==================

从我的电子邮件地址中删除x

Jerry Stuckle

JDS计算机培训公司

jstuck .. 。@ attglobal.net

================== - 隐藏引用的文字 -


- 显示引用文本 -



Jerry,


感谢您的回复。是的,我查看了源代码,但没有< ; br>,

所有我得到的是一个新的空白行,我们知道它被浏览器忽略了。




" Michael" < Mi *************** @ yahoo.com在留言中写道

新闻:11 *************** *******@j4g2000prf.googlegro ups.com ...


我是PHP新手。


我看到PHP支持C printf函数,我看过例如

就像printf(Hello world!\ n);但是换行符\\ n \\ n \\ n
无法正常工作 - 也就是说,它不会生成HTML< br> ;,我会b / b
预期 - 它是什么确实是在html

生成的文本中生成换行符,但由于浏览器忽略了空行,因此对于大多数应用程序来说,这个

功能似乎没用。


>>由此产生两个问题:



1.我误解了什么?


2.将换行符插入PHP

字符串的规定方法是什么? (可能是printf(Hello world!< br>)?



是。


更多正确


printf(Hello world!< br> \\\\ n);


所以你得到一条线打破源HTML,让你更容易阅读
.


或者,因为你实际上没有格式化任何东西:


print(" Hello world!< br> \\\\ n");


甚至


echoHello world!< br> \\ n \\ n;;


-

Richard。


I''m new to PHP.

I see that PHP supports the C printf function, and I''ve seen examples
like printf("Hello world!\n"); however the newline character \n
doesn''t work - i.e., it does not generate an HTML <br>, which I would
have expected - what it does is generate a newline in the html
generated text, but since the browser ignores blank lines, this
feature appears useless for most applications.

>From this arises two questions:

1. I am misunderstanding something?

2. What is the prescribed way of inserting a newline into a PHP
string? (Could it be printf("Hello world! <br>") ?

Thanks,
M. McDonnell

解决方案

Michael wrote:

I''m new to PHP.

I see that PHP supports the C printf function, and I''ve seen examples
like printf("Hello world!\n"); however the newline character \n
doesn''t work - i.e., it does not generate an HTML <br>, which I would
have expected - what it does is generate a newline in the html
generated text, but since the browser ignores blank lines, this
feature appears useless for most applications.

>>From this arises two questions:


1. I am misunderstanding something?

2. What is the prescribed way of inserting a newline into a PHP
string? (Could it be printf("Hello world! <br>") ?

Thanks,
M. McDonnell

It works fine. It generates a nl character, just as you asked it to.
Look at your source code - you''ll see the line break.

If you want an HTML <bror xthtml <br />, you need to code them
yourself. PHP does not convert for you.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


On May 27, 8:05 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:

Michael wrote:

I''m new to PHP.

I see that PHP supports the C printf function, and I''ve seen examples
like printf("Hello world!\n"); however the newline character \n
doesn''t work - i.e., it does not generate an HTML <br>, which I would
have expected - what it does is generate a newline in the html
generated text, but since the browser ignores blank lines, this
feature appears useless for most applications.

>From this arises two questions:

1. I am misunderstanding something?

2. What is the prescribed way of inserting a newline into a PHP
string? (Could it be printf("Hello world! <br>") ?

Thanks,
M. McDonnell


It works fine. It generates a nl character, just as you asked it to.
Look at your source code - you''ll see the line break.

If you want an HTML <bror xthtml <br />, you need to code them
yourself. PHP does not convert for you.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -

Jerry,

Thanks for your reply. Yes, I looked at the source code, but no <br>,
all I get is a new line of white space, which as we know is ignored by
the browser.



"Michael" <Mi***************@yahoo.comwrote in message
news:11**********************@j4g2000prf.googlegro ups.com...

I''m new to PHP.

I see that PHP supports the C printf function, and I''ve seen examples
like printf("Hello world!\n"); however the newline character \n
doesn''t work - i.e., it does not generate an HTML <br>, which I would
have expected - what it does is generate a newline in the html
generated text, but since the browser ignores blank lines, this
feature appears useless for most applications.

>>From this arises two questions:


1. I am misunderstanding something?

2. What is the prescribed way of inserting a newline into a PHP
string? (Could it be printf("Hello world! <br>") ?

Yes.

More properly

printf("Hello world! <br>\r\n");

so you get a line break in the source HTML as well, making it easier to
read.

or, since you are not actually formatting anything:

print("Hello world! <br>\r\n");

or even

echo "Hello world! <br>\r\n";

--
Richard.


这篇关于printf中的换行符(\ n)不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆