码迷,mamicode.com
首页 > Web开发 > 详细

php中echo简单用法

时间:2017-05-20 13:54:44      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:false   syntax   this   cap   const   var   int   自己   bar   

初学者,被echo语法困扰,查看,求各位大神指点!!!

手册上写echo — 输出一个或多个字符串,而字符串有单引号,双引号以及定界符。

单引号只会输出字符本身,双引号会输出变量,手册上写的已经很详细了。

 

<?php
echo "Hello World";

echo "This spans
multiple lines. The newlines will be
output as well";
//
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
//
echo "Escaping characters is done \"Like this\".";

// 你可以在回声语句里面使用变量
$foo = "foobar";
$bar = "barbaz";

echo "foo is $foo"; // foo is foobar

// You can also use arrays
$baz = array("value" => "foo");

echo "this is {$baz[‘value‘]} !"; // this is foo !

// 使用单引号将打印变量名,而不是值
echo ‘foo is $foo‘; // foo is $foo

// 如果您没有使用任何其他字符,您可以只返回变量
echo $foo;          // foobar
echo $foo,$bar;     // foobarbarbaz

// 字符串可以作为多个参数单独传递或连接在一起并作为一个参数传递
echo ‘This ‘, ‘string ‘, ‘was ‘, ‘made ‘, ‘with multiple parameters.‘, chr(10);
echo ‘This ‘ . ‘string ‘ . ‘was ‘ . ‘made ‘ . ‘with concatenation.‘ . "\n";
//
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;

// 因为回声不象一个函数,下面的代码是无效的。
($some_var) ? echo ‘true‘ : echo ‘false‘;

// 然而,下面的例子将工作:
($some_var) ? print ‘true‘ : print ‘false‘; // print is also a construct, but
                                            // it behaves like a function, so
                                            // it may be used in this context.
echo $some_var ? ‘true‘: ‘false‘; // changing the statement around
?>

 

我自己写的代码

echo "{$match[0][0]}"."\n"."{$match[0][1]}"."\n"."{$match[0][2]}"."\n"."{$match[0][3]}"."\n"."{$match[0][4]}";

echo "{$match[0][0]}","\n","{$match[0][1]}","\n","{$match[0][2]}","\n","{$match[0][3]}","\n","{$match[0][4]}";

//可见,不同的字符表变量可以用英文.|,隔开,在加上转义符,这样每输出一个数组就换一行,要输出数组的话,最好用大括号包括。

只能作为连续字符串输出

echo ‘wo zai zhe‘."\n".‘huanhang‘;

php中echo简单用法

标签:false   syntax   this   cap   const   var   int   自己   bar   

原文地址:http://www.cnblogs.com/xiaolongui/p/6881984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!