Basic PHP Examples

PHP Example #1: Output, Variables, Built-In Function


				<?php
					echo "<p>Hello World!</p>";

					echo "<p>\"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program.\" - Linus Torvalds</p>";

					echo "<p>Today is " . date("l n/j/Y") . "</p>";

					echo "<p>Go to <a href=\"https://www.w3schools.com/css/\">W3Schools CSS Tutorial</a></p>";
				?>
				

Run it now

PHP and JavaScript Example #2: Variables, Built-in Function, Math


					<?php
						$num1 = random_int(1, 12);
						$num2 = random_int(1, 12);
						$total = $num1 * $num2;

						echo "<p>Random times table example: $num1 * $num2 = _______</p>";
					?>			
					

Run it now

PHP Example #3: Outputting an HTML List


								<?php
									echo '<p>Ethics and Responsibility in IT</p>
										  <ol>
											  <li><a href="https://www.acm.org/code-of-ethics">ACM Code of Ethics and Professional Conduct</a></li>
											  <li><a href="https://www.ieee.org/about/corporate/governance/p7-8">IEEE Code of Ethics</a></li>
											  <li><a href="https://www.sans.org/white-papers/1535">SANS IT Code of Ethics</a></li>
										  </ol>';
								?>
								

Run it now