HTTP päiste probleem include'iga PHP-s

HTTP päistega probleem võib tekkida ka failide include'imisel läbi include. See ilmneb juhul, kui pärast sulgevaga ?> on pandud tühikud või tühjad read, nagu näiteks nii:

file.php<?php
  // some code
?>

 

Sel juhul, kui me include'ime oma faili teise faili, mõjuvad jäetud tühjad read nagu ekraanile väljund:

index.php<?php
  include 'file.php'; // sees on ekraanile väljund
  
  header('Content-Type: text/html');
?>

Probleemi lahendamiseks on kõige parem kõigis PHP failides eemaldada viimane sulgev ?>. Selline võte ei põhjusta PHP veateadet ja samas kaitseb meid juhuslikult lisatud tühjade ridade eest. Parandame meie faili:

file.php<?php
  // some code
  
   
Задание 1

Parandage järgnevas koodis tehtud vead:

file1.php<?php
  function func1() {
    echo '1';
  }
?>

 
file1.php<?php
  function func2() {
    echo '2';
  }
?>

 
index.php<?php
  include 'file1.php';
  include 'file2.php';
  header('Content-Type: text/html');
?>

 
Задание 2

Parandage järgnevas koodis tehtud vead:

file.php<?php
  function func1() {
    echo '1';
  }
?>
<?php
  function func2() {
    echo '2';
  }
?>
 
index.php<?php
  include 'file.php';
  header('Content-Type: text/html');
?>