Understanding PHP basics: Difference between revisions
From Leechfinger
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 25: | Line 25: | ||
error_reporting( E_ALL ); | error_reporting( E_ALL ); | ||
ini_set( "display_errors", 1); | ini_set( "display_errors", 1); | ||
</syntaxhighlight> | |||
== HTML5 page with php == | |||
<syntaxhighlight lang="php" line> | |||
<?php | |||
$title = "Test title"; | |||
$content = "<h1>Hello World</h1>"; | |||
$page = " | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<title>$title</title> | |||
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/> | |||
</head> | |||
<body> | |||
$content | |||
</body> | |||
</html>"; | |||
echo $page; | |||
?> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:PHP]] | [[Category:PHP]] |
Revision as of 15:06, 25 May 2024
Get PHP info
<?php
phpinfo();
?>
Let's write our first PHP code.
<?php
echo "Hello from PHP";
?>
Storing values in a variable
<?php
$myName = "Kooka";
$friendsName = "Loopa";
echo "<p>I am $myName and I have a friend called $friendsName.</p>";
?>
Display errors
Insert the following two lines at the top of your scripts to display errors.
error_reporting( E_ALL );
ini_set( "display_errors", 1);
HTML5 page with php
<?php
$title = "Test title";
$content = "<h1>Hello World</h1>";
$page = "
<!DOCTYPE html>
<html>
<head>
<title>$title</title>
<meta http-equiv='Content-Type' content='text/html;charset=utf-8'/>
</head>
<body>
$content
</body>
</html>";
echo $page;
?>