如何使用换行标签来回显不止一件事?

发布于 2024-10-22 06:17:32 字数 368 浏览 1 评论 0原文

我目前正在使用下面的代码来回显一些不同的变量和 2 个换行符。

但我想知道的是如何将所有变量(包括换行符)回显到一行代码中?

<?php

function findworld($var) {
    return strpos($var, "world");
}

$firstvar = "hello world";
$secondvar = findworld($firstvar);
$thirdvar = strlen($firstvar);

echo $firstvar;
echo "<br />";
echo $secondvar;
echo "<br />";
echo $thirdvar;
?>

I am currently using the below code to echo a few different variables and 2 line breaks.

But what I would like to know is how can I echo all of the variables including line breaks into one line of code?

<?php

function findworld($var) {
    return strpos($var, "world");
}

$firstvar = "hello world";
$secondvar = findworld($firstvar);
$thirdvar = strlen($firstvar);

echo $firstvar;
echo "<br />";
echo $secondvar;
echo "<br />";
echo $thirdvar;
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一个人的夜不怕黑 2024-10-29 06:17:32

php 中的连接运算符是“.”

echo $firstvar . "<br />" .  $secondvar .  "<br />" . $thirdvar;

http://www.php.net/manual/en/language.operators .string.php

the concat operator in php is "."

echo $firstvar . "<br />" .  $secondvar .  "<br />" . $thirdvar;

http://www.php.net/manual/en/language.operators.string.php

油饼 2024-10-29 06:17:32

您可以将多个参数传递给 echo ,用逗号分隔:

echo $firstvar, "<br />", $secondvar, "<br />", $thirdvar;

为了避免重复换行,您还可以使用 内爆

$firstvar = "hello world";
$values = array($firstvar, 
                findworld($firstvar), 
                strlen($firstvar));

echo implode('<br />', $values);

You can pass multiple parameters to echo, separated by a comma:

echo $firstvar, "<br />", $secondvar, "<br />", $thirdvar;

To avoid repeating the line break, you could also use implode:

$firstvar = "hello world";
$values = array($firstvar, 
                findworld($firstvar), 
                strlen($firstvar));

echo implode('<br />', $values);
揽月 2024-10-29 06:17:32

您可以使用字符串连接:

echo $firstvar . "<br />" . $secondvar . "<br />" . $thirdvar;

You can use string concatenation:

echo $firstvar . "<br />" . $secondvar . "<br />" . $thirdvar;
北方的韩爷 2024-10-29 06:17:32

就像其他人所说的那样,但在所有正确的位置都有语音标记;)

echo $firstvar.'<br />'.$secondvar.'<br />'.$thirdvar;

Like others have said, but with speech marks in the all the correct places ;)

echo $firstvar.'<br />'.$secondvar.'<br />'.$thirdvar;
冷心人i 2024-10-29 06:17:32

您根本不需要用双引号连接,您可以:

echo "$firstvar<br />$secondvar<br />$thirdvar";

You don't need to concatenate at all with double quotes, you can just:

echo "$firstvar<br />$secondvar<br />$thirdvar";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文