PHP/Utility Function/echo

Материал из Web эксперт
Версия от 07:07, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Add lines and spaces to textarea

 
<html>
<?php
  echo("<textarea>");
  echo("\"as dfas dfa sdf!\"");
        echo("\n(one!)");
        echo("\n\n \t\t\t data ");
  echo("</textarea>");
?>
</html>



A Simple "Hello World" Script

 
<HTML>
<HEAD><TITLE>My First PHP Script</TITLE></HEAD>
<BODY>
<?php
       echo "Hello, world!"; 
?>
</BODY>
</HTML>



Correct escaping of special characters

 
<?php
echo "<h2 class=\"specialH2\">M!</h2>";
echo "<h2 class="specialH2">M!</h2>";
?>



echo is more useful because you can pass it several parameters

 
<?php
            echo "This ", "is ", "a ", "test.";
    ?>



Echo out html tags

 
<html>
<?php echo( "<h1>Hello World</h1>" ); ?>
</html>



echo versus print

 
<?php
(12 == $status) ? print "Status is good" : error_log("Problem with status!");
?>



embedded variables are handled when the string is created with single or double quotes.

 
<?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"; 
?>



Enclosure html into a string and echo out

 
<html>
<?php
  $str = "<textarea rows=\"5\" cols=\"48\">\"this is a test!\"\n(test!)\n\n \t\t\t Caligula </textarea>";
  echo( $str );
?>
</html>



Formatting of Numeric Data

 
<?php
$i = 123;
$f = 12.567;
echo "\$i = $i and \$f = $f\n";
?>



how arrays embedded in strings will be converted.

 
<?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";
?>



Key-value array elements

 
<html>
 <head>
  <title>Key-value array elements</title>
 </head>
 <body>
  <ol>
  <?php
  $arr = array( "version" => 10, "OS"=> "Linux", "os" => " Mandrake ");
  
  echo("Platform: ". $arr["OS"]. $arr["os"]. $arr["version"]);
  ?>
  </ol>
 </body>
</html>