Basic PHP functions

Great site where all the PHP basics such as syntax, variables, classes, pointers, object oriented stuff, file I/O, and various functions are outlined:

Also, please visit this for pre-defined functions in PHP to use:

Example of a simple Guess My Number PHP program:

<!--Here is the code for Guess My Number in PHP, a program that generates a random number between 1 and 100 and asks the user to guess it.
It will tell the user if the number is higher or lower after each guess.
This is just one way to write it in PHP. -->

<title>Guess My Number (PHP)</title>
<h1>Guess My Number (PHP)</h1>

<form method="post" action="<?= $_SERVER['PHP_SELF'];?>">
Guess My Number (1-100): <input type="text" id="guess" name="guess" size=3>
<input type="submit" value="Guess" name="Guess_Button">

<!-- php code goes here -->
	$y = $_POST['number'];
	$y = rand(1,100);
$x = $_POST['guess'];
$value = $_POST['number'];//retrieve the random value from the hidden html element and assign to a variable

if($x < $value)
	echo $x." is wrong, guess Higher";
if($x > $value)
	echo $x." is wrong, guess Lower";
if($x == $value)
	echo $value." is Correct!";
<!-- we use the hidden html element to store the random value -->
<input name="number" type="hidden" value="<?= $y ?>"/>

<a href="gmn.php">Play Again</a>



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s