Résolu Comment faire un include en PHP ?

Sparta.

THIS IS SPARTA !
Premium
Inscription
31 Mars 2012
Messages
864
Réactions
199
Points
4 133
Bonjour,

Je n'arrive pas à faire fonctionner mon include.
HTML (index.html) :
HTML:
<!doctype html>
<html lang="fr">
    <head>
          <meta charset="utf-8">
          <title>Stream</title>
          <link rel="stylesheet" href="css\style.css"/>
    </head>
    <body>
       

        <?php include("nav.php"); ?>

et le PHP (nav.php) à inclure :
HTML:
<h1 class="title"> <a href="index.html"> Squad Stream</a><h1/>

    <nav>
        <p>
            <ul>
                <li><a href="index.html">Films</a></li>
                <li class="pandding"><a href="series.html">Series</a></li>
                <li><a href="mangas.html">Mangas</a></li>
            </ul>
        </p>
    </nav>

Merci de votre aide :)
 
Dernière édition:

Rivals

Ancien staff
Inscription
27 Août 2016
Messages
1 705
Réactions
895
Points
13 104
Salut :membre:,

Tu veux inclure ton fichier PHP dans ton fichier HTML ? Si oui, il faut renommer ton fichier HTML pour ajouter l'extension .php et ajouter le morceau de code suivant (si le fichier PHP se trouve dans le même répertoire que ton fichier HTML).

Code:
<?php include 'nav.php'; ?>

Bonne journée,
Rivals
 

Sparta.

THIS IS SPARTA !
Premium
Inscription
31 Mars 2012
Messages
864
Réactions
199
Points
4 133
Ton fichier doit avec l'extension .php et non .html ^^
J'ai changé mais toujours le même probléme, il ne s'affiche pas :'(

<?php include 'nav.php'; ?>
J'ai essayé, ça ne marche pas

Salut :membre:,

Tu veux inclure ton fichier PHP dans ton fichier HTML ? Si oui, il faut renommer ton fichier HTML pour ajouter l'extension .php et ajouter le morceau de code suivant (si le fichier PHP se trouve dans le même répertoire que ton fichier HTML).

Code:
<?php include 'nav.php'; ?>

Bonne journée,
Rivals
J'ai fais ça, rien ne change :(
 
Dernière édition par un modérateur:

Wariie

Dév C/Java | IUT INFO
Premium
Inscription
29 Juillet 2013
Messages
1 808
Réactions
560
Points
10 343
tu rénomme ton index.html en index.php ensuite dans fichier nav.php tu fias une fonction comme :

Code:
function affich_nav (){
 
   echo  ' //ton html ';

}

en suite ton index.php tu fais
Code:
<?php
    include nav.php;
    affich_nav();
?>
 
Cette réponse a aidé l'auteur de cette discussion !

WhiiTe'

Administateur
Ancien staff
Inscription
22 Octobre 2011
Messages
14 706
Réactions
8 492
Points
32 425
tu rénomme ton index.html en index.php ensuite dans fichier nav.php tu fias une fonction comme :

Code:
function affich_nav (){
 
   echo  ' //ton html ';

}

en suite ton index.php tu fais
Code:
<?php
    include nav.php;
    affich_nav();
?>

C'est du code inutile, autant mettre direct l'html dedans et inclure le nav.php à sa place :mmh:
 
D

deleted517474

comment ça ? il ne va pas se placer au bon endroit aprés

Perso moi :

PHP:
<?php
    include 'config/config.php';
    error_reporting(0);
    $api = json_decode(file_get_contents("http://mcapi.ca/query/$serverIP/players"), true);
    $onlinePlayers = 0;
    if ($api['status']) {
        $onlinePlayers = $api['players']['online'];
    }
    include('config/config.php');
    if($maintenance == "true")
    {
    include('maintenance.php');
    }

?>


<html>
    <head>
        <title><?php echo $serverName ?> | Portail</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <meta name="robots" content="index,follow">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="assets/css/styles.css">
        <link rel="stylesheet" href="assets/css/bootstrap.css">
        <meta name="description" content="Site réalisé par Antoine">
        <link rel="stylesheet" href="assets/css/font-awesome.css">
    </head>
<body>

Et cela fonctionne
 
Haut