PHP/Development/Echo
Версия от 10:37, 26 мая 2010; (обсуждение)
Содержание
Echoing a String
<html>
<head>
<title>Echo Example</title>
</head>
<body>
<?php
$string1 = "A.<br />\n";
$string2 = "B ";
$string3 = "Line 1
spans multiple lines.
Line3<br />";
echo "Start, ", $string2, $string1;
echo("$string2$string1");
echo("This string $string1");
echo($string2 . $string1);
echo($string3);
echo "Line 1.
lin 2!!<br />";
?>
<?=$string2,$string1?>
<?="output", " wbex.ru!", "<br />", ":-)", "<br />\n" ?>
<?="This string
spans multiple lines.
Even the newlines are output in the document source!<br />"?>
</body>
</html>
Echo multiline string
<?php
$website = "http://www.wbex.ru";
echo <<<EXCERPT
<p>Line 1
Line 2
Line 4
$website
EXCERPT;
?>
Echo variables
<?
$var1 = "PHP";
$var2 = 5;
$var3 = $var2 + 1;
$var2 = $var1;
echo($var1);
echo($var2);
echo($var3);
echo($var1 . " rules!");
echo("$var1 rules!");
echo("$var1 rules!");
?>
Escape the inner quotation marks by placing a backslash before each one
<?
echo "<P>I think this is
really \"cool\"!</P>";
?>
Use echo command to output HTML
<?
echo "<P>Line one</P>";
echo "<P>Line 2</P>";
?>
Use Echo command to output HTML string
<html>
<head>
<title> Simple PHP Example </title>
</head>
<body>
<p><?php echo("This is a <b>test</b>!"); ?></p>
</body>
</html>
Use Echo to output string
<?php
echo("PHP is a great programming language, isn"t it?");
?>