PHP/Language Basics/Include — различия между версиями

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

Текущая версия на 07:05, 26 мая 2010

Test of PHP Includes

<!-- include-me.php
<?php
  echo( "<p>"from included file!"</p>" );
?>
-->
<html>
<head>
<title> Test of PHP Includes </title>
</head>
<body>
<?php
  include("include-me.php");
?>
</body>
</html>



Using include()

<html>
<head>
<title>Using include()</title>
</head>
<body>
<?php
include("myIncludeFile.php");
?>
</body>
</html>
<!-- myIncludeFile.php
<?php
print "included!!<BR>";
print "4 + 4 = ".(4 + 4);
?>
-->



Using include() to Execute PHP and Assign the Return Value

<html>
<head>
<title>Using include() to execute PHP and assign the return value</title>
</head>
<body>
<?php
    $addResult = include("myIncludeFileWithReturnValue.php");
    print "The include file returned $addResult";
?>
</body>
</html>
<!-- myIncludeFileWithReturnValue.php
<?php
$retval = ( 4 + 4 );
return $retval;
?>
-->



Using include() Within a Loop

<html>
<head>
<title>Using include() within a loop</title>
</head>
<body>
<?php
for ( $x = 1; $x<=3; $x++ ) {
   $incfile = "incfile$x".".txt";
   print "Attempting include $incfile<br>";
   include( "$incfile" );
   print "<p>";
}
?>
</body>
</html>