PHP/Utility Function/echo
Содержание
Add lines and spaces to textarea
<source lang="html4strict">
<html> <?php
echo("<textarea>"); echo("\"as dfas dfa sdf!\""); echo("\n(one!)"); echo("\n\n \t\t\t data "); echo("</textarea>");
?> </html>
</source>
A Simple "Hello World" Script
<source lang="html4strict">
<HTML> <HEAD><TITLE>My First PHP Script</TITLE></HEAD> <BODY> <?php
echo "Hello, world!";
?> </BODY> </HTML>
</source>
Correct escaping of special characters
<source lang="html4strict">
<?php
echo "M!
"; echo "M!
";?>
</source>
echo is more useful because you can pass it several parameters
<source lang="html4strict">
<?php
echo "This ", "is ", "a ", "test."; ?> </source>
Echo out html tags
<source lang="html4strict">
<html>
<?php echo( "Hello World
" ); ?></html>
</source>
echo versus print
<source lang="html4strict">
<?php (12 == $status) ? print "Status is good" : error_log("Problem with status!"); ?>
</source>
embedded variables are handled when the string is created with single or double quotes.
<source lang="html4strict">
<?php
$a = 10; $b = 15.7; echo "The value of \$a is $a and the value of \$b is $b\n"; echo "The value of \$a is $a and the value of \$b is $b\n";
?>
</source>
Enclosure html into a string and echo out
<source lang="html4strict">
<html> <?php
$str = "<textarea rows=\"5\" cols=\"48\">\"this is a test!\"\n(test!)\n\n \t\t\t Caligula </textarea>"; echo( $str );
?> </html>
</source>
Formatting of Numeric Data
<source lang="html4strict">
<?php $i = 123; $f = 12.567; echo "\$i = $i and \$f = $f\n"; ?>
</source>
how arrays embedded in strings will be converted.
<source lang="html4strict">
<?php $arr = array(
1 => "abc", "abc" => 123.5, array(1,2,3)
); $key = "abc"; echo "First value = $arr[1]\n"; echo "Second value = $arr[abc]\n"; echo "Third value = $arr[2]\n"; echo "Third value = $arr[2][2]\n"; echo "Second value = ${arr["abc"]}\n"; echo "Second value = ${arr["abc"]}\n"; echo "Second value = ${arr[$key]}\n"; ?>
</source>
Key-value array elements
<source lang="html4strict">
<html>
<head> <title>Key-value array elements</title> </head> <body>
-
<?php
$arr = array( "version" => 10, "OS"=> "Linux", "os" => " Mandrake ");
echo("Platform: ". $arr["OS"]. $arr["os"]. $arr["version"]);
?>
</body>
</html>
</source>