Start Learning Very Simple PHP

Ranked #13,047 in Computers & Electronics, #270,768 overall

Learn PHP with these Really Simple Scripts

This Lens is designed to encourage non-techies to start learning PHP the Web's most popular Scripting Language. It does this by listing very simple scripts that are designed to give Newbies confidence.

Lots of the most popular website applications are written using PHP. So a website form, quiz or poll might use PHP. Wordpress the very popular blogging platform uses PHP. Normally you can download and install the above PHP applications, without any technical knowledge; however sooner or later even non-techies get the urge to customize....

Hello World

This is the simplest script possible, meant for beginners

<?php ="Hello world" ?>

this can also be written

<?php echo "Hello world" ?>

And will simply display "hello world" on your web page. Not very useful but it's a first step.

<?php echo "<h2>Hello world</h2>" ?> Now with HTML

What Web Skills are Beefing up?

Loading poll. Please Wait...

Make Today's Date Appear on your Webpage

<?php echo date(); ?>

You can also format the date
<?php echo date("Y-m-d H:i:s"); ?>

How to Find out if you have PHP installed on your Website

Create a file test.php with notepad or better
Containing
<?php phpinfo(); ?>

FTP this up to your Website and execute with
http://www.mywebsite.com/test.php

If PHP is enabled on your website then 3 or 4 screens of details about your PHP installation will appear.

PHP is normally available on websites you have purchased, as apposed to most "free" websites

Simple Maths

Doesn't do anything useful

<?php $sum=1+2+7; ?>

The Sum is <?php echo $sum ?>

PHP Books on Amazon

Loading

Making Decisions

if-elseif-else this is the core of programming logic

<php
$dayofweek = date('D');
if ($dayofweek=='Mon')
{
echo "It's Monday";
}
else
{
echo "It's not Monday";
}
?>

Display your URL/domain Name

<?php

echo $_SERVER['HTTP_HOST'];

?>

PHP Web Links

PHP Main Website
The Main PHP Website for downloads and documentation
PHP on Wikipedia
Great Overview
PHP Tutorial
Free PHP tutorials, references, examples for web building.

Outputting blocks of text or HTML

The normal way of outputting text is

echo 'Here is some text';

or

echo "I am $age years old";

However when you want to output a lot of text that may contain single or double quotes, the "heredoc" shown below is more elegant

echo <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;

Learn more here php.net/types.string

PHP on CafePress

Loading

PHP on eBay

Loading

PHP Guestbook

What would you like to see?

submit
  • Reply
    tssfacts Oct 13, 2010 @ 10:04 am | delete
    Good lesson in PHP. I really need to take some time and learn more about this coding. It's on my long lists of things to do lol.
  • Reply
    sbucciarel Aug 25, 2008 @ 3:17 pm | delete
    Great lense. The Firestorm Forum is great for promoting your lenses and blogs. There's a very active Squidoo community there. firestormforum.com Hope you check it out. I also have a lense about it at http://www.squidoo.com/firestorm

Learn More About PHP

Is there a better book out there? If so list it below.

created by giltotherescue

by

thesuccess

Why not Measure your Squidoo Progress Here find out what your Squidoo Goals are!

Find out if you are a Ripple Maker or a Scanner or do you want to
more »

Feeling creative? Create a Lens!