PHP 中的新行(“ ")不起作用 [英] New line (" ") in PHP is not working

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

问题描述

由于某些奇怪的原因,插入 echo " "; 和其他 scape 序列字符对我不起作用,这就是为什么我只使用 <br/> 代替.

For some strange reason, inserting echo " "; and other scape sequence characters are not working for me, that's why I am just using <br /> instead.

书籍和其他文档中示例结果的图像看起来还不错.我目前正在使用 XAMPP,并且已经使用了具有相同实际结果的 WAMPP.这是为什么?

The images of the results of examples in books and other documentations seems just alright. I'm currently using XAMPP and already used WAMPP with the same actual result. Why is that?

在将您的答案与以下内容进行比较后,我似乎无法理解这个概念:PHP 换行符 ( ) 不工作

It seems that I cannot understand the concept after comparing your answers with this: PHP Linefeeds ( ) Not Working

对不起,我没有意识到上面的链接是指写入文件的 php 代码.我只是想知道为什么我有这些使用 的几个 php 示例程序,即使它在网页中输出.谢谢大家.

Sorry I didn't realized that the link above is referring to a php code writing to a file. I just wonder why I have these few php sample programs that uses even though it outputs in a webpage. Thanks everyone.

推荐答案

当你在浏览器中运行 PHP 脚本时,默认情况下它会呈现为 HTML.如果您使用的书籍另有显示,则代码或插图不准确.您可以使用“查看源代码”查看发送到浏览器的内容,您将看到您的换行符存在.

When you run a PHP script in a browser, it will be rendered as HTML by default. If the books you’re using show otherwise, then either the code or the illustration is inaccurate. You can use “view source” to view what was sent to the browser and you’ll see that your line feeds are present.

<?php
echo "Line 1
Line 2";
?>

这将在您的浏览器中呈现为:

This will render in your browser as:

Line 1 Line 2

如果您需要向浏览器发送纯文本,您可以使用以下内容:

If you need to send plain text to your browser, you can use something like:

<?php
header('Content-type: text/plain');
echo "Line 1
Line 2";
?>

这将输出:

Line 1
Line 2

PHP Linefeeds ( ) Not Working 是指将输出发送到文件而不是浏览器.

PHP Linefeeds ( ) Not Working is referring to sending output to a file rather than the browser.

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

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