I am new to HTML and PHP and currently trying to build my first pages.
I am getting the following error trying to compile the code:
PHP Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/Z6XJiZ/prog.php on line 45
Here is the code:
<?php
header('Content-Type: text/html; charset=utf-8');
echo <<< HTML
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>First-Page</title>
</head>
<body>
HTML;
echo <<< HTML
<header>
<h1>Header</h1>
<img alt="A Cat" src="https://media.istockphoto.com/photos/cat-hunting-to-mouse-at-home-burmese-cat-face-before-attack-closeup-picture-id1313021528?s=612x612" class="w-50 h-auto">
</header>
HTML;
$data = [
0 => [
'link' => 'https://www.youtube.com/',
'text' => 'youtube',
],
1 => [
'link' => 'https://www.google.com/',
'text' => 'google',
],
2 => [
'link' => 'https://www.wikipedia.com/',
'text' => 'wikipedia',
],
];
foreach($data as $item) {
$link = $item['link'];
$linkText = $item['text'];
echo <<< HTML
<a href="$link" target="_blank">$linkText</a>
HTML;
}
if(isset($_POST['name'])) {
echo '<section>';
echo '<h2>From-data is available</h2>';
echo '<p>' . $_POST['name'] . '</p>';
echo '</section>';
}
echo <<< HTML
<section>
<h2>Content</h2>
<p>Here a form is sent to yourself.</p>
<form action="live-coding.php" method="post" accept-charset="utf-8">
<p>
<label for="myname">Name</label><br>
<input id="myname" type="text" name="name" value="" required placeholder="enter name">
</p>
<p>
<input type="submit" value="Sent">
</p>
</form>
</section>
<footer class="container">
<h2>Footer</h2>
<p><small>Test Page ©</small></p>
</footer>
HTML;
echo <<< HTML
</body>
</html>
HTML;
Couldn't find any solutions to my problems. Whatever I tried it resulted in more problems/errors...