Here are some introductory PHP examples. To run them examples on your VM (which already has PHP installed for your convenience)...
- Login to your VM
git clone http://github.com/portsoc/introphp.git
php -S 0:8080 -t introphp
- Check the IP address of your VM, and type this into your preferred browser to load a copy of this page from your server. From there you can try the examples, and then change them to your specifications.
- If you're using Chrome, try Mike's LivePage extension to update the browser content as you change the source files.
- For editing the files on server, you can use
nano
as a simple text editor (ctrl-o
to save, andctrl-x
to exit); or edit on your computer and upload the files to the server on every change. - If you're using Atom, the Remote Sync package (or similar ones) may help you with the uploads.
- The basic Hello World Program
- Hello World Program with Variables and Concatenation
- Hello World with Variables and Template Strings
- Simple arithmetic
- Simple arithmetic with parameters and variables - a, b.
- Message loop - msg, count.
- Conditional Message loop - msg, count, mod.
- PHP has a several special variables containing useful data.
- The special
phpinfo()
function.
- Getting data from forms - name.
- Storing a list of visitors - visitors.txt.