drmy1050
drmy1050
2011-03-13 14:17
浏览 37
已采纳

你怎么用换行标签回应多个东西?

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;
?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • dongyue9864
    dongyue9864 2011-03-13 14:21
    已采纳

    the concat operator in php is "."

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

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

    点赞 评论
  • dry9192
    dry9192 2011-03-13 14:19

    You can use string concatenation:

    echo $firstvar . "<br />" . $secondvar . "<br />" . $thirdvar;
    
    点赞 评论
  • doumou5109
    doumou5109 2011-03-13 14:20

    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);
    
    点赞 评论
  • dsfdsf23423
    dsfdsf23423 2011-03-13 14:23

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

    echo $firstvar.'<br />'.$secondvar.'<br />'.$thirdvar;
    
    点赞 评论
  • dongshi6529
    dongshi6529 2011-03-13 14:23

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

    echo "$firstvar<br />$secondvar<br />$thirdvar";
    
    点赞 评论

相关推荐