Qual é a melhor forma de integrar meu php ao html?
Exemplo 1:
Script php dentro do html:
index.php
<?php
echo "meu script";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
Exemplo 2:
Chamando o php externo no html:
index.php
<?php
require 'teste.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
Exemplo 3:
Chamando o php por ajax no js:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id="txt"></p>
</body>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txt").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "teste.php?", true);
xmlhttp.send();
</script>
</html>
Qual é melhor meio?
Lembrando que gostaria de dividir as coisa tipo html só com html e php só com php.