<!doctype html>
<html lang = "fr">

<head>
<title>Our Funky HTML JSON manipulation Page</title>
<meta name="description" content="Our first page">
<meta name="keywords" content="html tutorial template">
<link rel="stylesheet" type="text/css" href="bostyle.css">
</head>
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"></script>

<script>
function ff (){
for(let i=0; i<10; i++)
console.log('fred'+i);
}
function fonction2 (msgerr){
console.log('f2')
//
$("#msgerr").css({"width":12, "height":16, "color":"red", "background-color":"#ff0"});
$("#msgerr").css("display", "inline-block");
$("#msgerr").empty().append(""+msgerr+"")
$("#msgerr").animate({"width": "100%"}, 1500, function() {
$("#msgerr").empty().append("<h3>DESOLE</h3>").css("height", 100);
});

}
</script>
<body onload="ff()">
<a class="toto titi" href="https://www.w3.org/">W3C Website</a> <p> ppp</p>
<div id="msgerr" style="overflow: hidden;display:none">ERREUR</div>
<?php
$file = file_get_contents('test.json');
$contenu = json_decode($file, true);

if (isset($_GET['delenf']))
array_splice($contenu['children'], $_GET['delenf'], 1);

else if (isset($_GET['nomenf']) && !in_array($_GET['nomenf'], $contenu['children']))
$contenu['children'][] = $_GET['nomenf'];

echo $contenu['first_name'].' a '.count($contenu['children']).' enfants <span onclick="fonction2(\'tu as appuyé trop tot\')">ICI</span><br>';
foreach ($contenu['children'] as $i => $v) {
echo '<div class="enf">'.$i.'<a href="json.php?delenf='.$i.'"><img width="12" src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Trash_%2889060%29_-_The_Noun_Project.svg/240px-Trash_%2889060%29_-_The_Noun_Project.svg.png"></a>'.$v.'</div>';
}
echo('<form action="json.php">
Nouvel enfant : <input type="text" name="nomenf">
<input type="submit" value="Ajouter">
</form>');
echo '<a href="json.php">raffraichir</a>';

$file = json_encode($contenu, JSON_PRETTY_PRINT);
file_put_contents('test.json',$file);
?>
</body>

</html>
Última modificación: miércoles, 5 de febrero de 2025, 10:00