Ik ben bezig met een soort blogsysteem maar nu heb ik een vraagje!
<?php
$post = json_decode( file_get_contents( 'json/post.json' ), true);
foreach ($post['post'] as $post) {
echo '
<p>
', $post['title'], '<br />
', $post['author'], '<br />
', $post['content'],'
</p>';
}
?>
<html>
<head>
<title>Blog Posts With JSON</title>
</head>
<body>
<form action="getpost.php" method="get">
<input type="text" name="post" />
<input type="submit" value="Get" />
</form>
</body>
</html>
ik heb dit script geschreven maar het werkt niet!
Ik krijg steeds deze fout: Warning: Invalid argument supplied for foreach() in C:\localhost\project\blog-posts-with-json\index.php on line 5.
Wat kan ik hieraan doen?
Mijn JSON:
"post":{
"0001": {
"title":"A Nice Title #1",
"author":"John Doe",
"content":"Hey, You can edit all of this stuff in post.json!"
},
"0002": {
"title":"Posts With JSON",
"author":"John Smith",
"content":"Hello, This is another post made with JSON!"
}
}
Ik ben net een beginner als het ligt aan JSON in php te verwerken. Wat eigenlijk mijn bedoeling is dat hij voor elke post hetzelfde stukje laat zien maardan met andere content voor elke post.
- Pascal Gerrist