PHP/Development/Echo

Материал из Web эксперт
Перейти к: навигация, поиск

Echoing a String

   <source lang="html4strict">

<html> <head> <title>Echo Example</title> </head> <body> <?php

    $string1 = "A.
\n"; $string2 = "B "; $string3 = "Line 1

spans multiple lines. Line3
";

    echo "Start, ", $string2, $string1;
    echo("$string2$string1");
    echo("This string $string1");
    echo($string2 . $string1);
    echo($string3);
    echo "Line 1.

lin 2!!
"; ?> <?=$string2,$string1?> <?="output", " wbex.ru!", "
", ":-)", "
\n" ?> <?="This string spans multiple lines. Even the newlines are output in the document source!
"?> </body> </html>

      </source>
   
  


Echo multiline string

   <source lang="html4strict">

<?php $website = "http://www.wbex.ru"; echo <<<EXCERPT

Line 1 Line 2 Line 4 $website EXCERPT; ?> </source>

Echo variables

   <source lang="html4strict">

<? $var1 = "PHP"; $var2 = 5; $var3 = $var2 + 1; $var2 = $var1; echo($var1); echo($var2); echo($var3); echo($var1 . " rules!"); echo("$var1 rules!"); echo("$var1 rules!"); ?>

      </source>
   
  


Escape the inner quotation marks by placing a backslash before each one

   <source lang="html4strict">

<? echo "<P>I think this is

really \"cool\"!

";

?>

      </source>
   
  


Use echo command to output HTML

   <source lang="html4strict">

<?

echo "

Line one

"; echo "

Line 2

";

?>

      </source>
   
  


Use Echo command to output HTML string

   <source lang="html4strict">

<html> <head> <title> Simple PHP Example </title> </head> <body>

<?php echo("This is a test!"); ?>

</body> </html>

      </source>
   
  


Use Echo to output string

   <source lang="html4strict">

<?php

  echo("PHP is a great programming language, isn"t it?");

?>

      </source>