This tutorial is a basic introduction to PHP for anyone in the heritage community.

What is PHP:
PHP: Hypertext Preprocessor is an open-source scripting language especially suited for web development (php.net). PHP script is executed on the server and does usually require a web server to run on. However, as you will see in this tutorial it is also possible to test your PHP scripts online without installing or hosting your own server. More on that later.

Why do I need PHP:
PHP is useful if you want to access and manipulate heritage datasets and present them in a webbrowser. You might have a database of heritage items or historic people that you want to publish online, or you may want to test and present an open heritage dataset in a new and interesting way on the web. PHP is very useful here.

<?php
/* first we declare
the variable $x and use it to
calculate the variable $y */
$x = 6;
$y = $x + 7; // the result is 13

# we can use PHP to print the result as a HTML top level header
echo "<h1>" . $y . "</h1>";

// we can create an array of artists
$artists = array("Anna", "Marie", "Anne");

// and use the foreach loop to display each artist with a lineā€break after
foreach ($artists as $person) {
    echo "$person <br>";
}

// we can create a function to call a particular artist from the array
function callArtist($i) {
    $artists = array("Anna", "Marie", "Anne");
    echo "Hi $artists[$i]";
}

// and execute the function with the second person (array index = 1)
callArtist(1); // result is "Hi Marie"
?>

  • Tutorial: Basic PHP
  • Skill: Beginners
Comments are closed.