Merge php with html

0

I'm starting with this PHP programming and after being fretting a bit doing some things I have a doubt.

I leave you an example of code with some conditions where I am fretting:

if ($mac_device === null) { 
echo "-- no se ha encontrado el vale o no está activo --";
} else {

foreach ($json_expired as $record) { 

    $mac = $record->mac;
    $status_expired = $record->expired;

    if ($mac_device === $mac) { 
        //echo "--[$mac]--";
        //echo "--[$mac_device]--";
        if ($status_expired != null) {
            echo "--EL VALE NO ESTA ACTIVO--"; 
            break;
        } else {
            echo "--EL VALE ESTA ACTIVO"; 
            $unifi_connection->unauthorize_guest($mac_device); 
            include 'create.php';
            break;
        }
    }
}}

The question I have is that if you combine this with HTML as I show you next, is the execution of the PHP code interrupted or would everything be executed the same as without the HTML that I have inserted?:

<?php

if ($mac_device === null) { 
?>
<head>  
</head>
<body>

<?php
echo "-- no se ha encontrado el vale o no está activo --";
?>

</body>     
<?php

} else {


foreach ($json_expired as $record) { 

    $mac = $record->mac;
    $status_expired = $record->expired;

    if ($mac_device === $mac) {             
        if ($status_expired != null) {

?>
<head>  
</head>
<body>

<?php
            echo "--EL VALE NO ESTA ACTIVO--";              
            break;
?>

</body>     
<?php           

        } else {


            echo "--EL VALE ESTA ACTIVO"; 
?>
<head>  
</head>
<body>

<?php           

            $unifi_connection->unauthorize_guest($mac_device); 
            include 'create.php';
            break;
        }
    }
}}

?>

Thanks for the help.

    
asked by Buendy 09.07.2018 в 12:26
source

1 answer

0

It is not interrupted. The fault you have is that you are opening several <head> and several <body> . And it is not necessary.

An HTML code consists of:

<head>
<!-- Aquí especificamos estilos, scripts, etc.. -->
</head>
<body>
<!-- Aquí introducimos el contenido de la web -->
</body>

Therefore, your code would be as follows:

<?php
if ($mac_device === null) { 
?>
<head>
<!-- Aquí especificamos estilos, etc. -->
</head>
<body>

<?php
echo "-- no se ha encontrado el vale o no está activo --";    
} else {

foreach ($json_expired as $record) { 

    $mac = $record->mac;
    $status_expired = $record->expired;

    if ($mac_device === $mac) {             
        if ($status_expired != null) {

            echo "--EL VALE NO ESTA ACTIVO--";              
            break;         

        } else {

            echo "--EL VALE ESTA ACTIVO";            
            $unifi_connection->unauthorize_guest($mac_device); 
            include 'create.php';
            break;
        }
    }
}}

?>
</body>
    
answered by 09.07.2018 / 12:33
source