First off I would like to say how much Pyython has influenced me to start coding in PHP. The basics of programming can be learned from scripting languages.
Just like any programming language PHP has varialbes
Much like any program a variable is assigned via the =
$variablle1 = 10;
Remember that a php expression has to end in a semicolon ;
so if variable1 is 10 if we echo it
<?php echo "$variable1;" ?>
will give us 10.
Also remember that whitespace does NOT matter in PHP so you can space it out however you like. This is different to python as python counts indents as actual code.
Running PHP code
IThe easiest way without getting into the nitty gritty would be to install XAMPP (https://www.apachefriends.org/) it’s basicall a W/L/MAMP stack that can run on just about any OS including windows, OSX and nix. Of course if you’re familliar with Linux you probably have the skill to install Apache and PHP, mysql on your own but I thought I’d give you the easy option.
I myself have a virtual machine running Debian and a LAMP stack with Samba. I mapped the network drive of my Debian virtual machine so I can edit the files directly. Not only this but I can save my files there so no uploading via FTP ,etc. Then when I’m done I just save the machine state, load it up again when I want to use it. But that’s just me. If you are a newbie using Windows I’d go with XAMPP it really is dead easy to setup and use.
Editing your Code
Depending on which platform you are on you may wish to use one program over another, nix enthusiast might want to use vim for example. Personally I like sublime text which is multi-platform. However recently I’ve been really liking Brackets; The reason I like brackets is because is has built in syntax highlighting, i know Sublime does too but Brackets also has live preview which lets you specify a server to run the code (important as we are writing PHP) so if you’re running XAMPP you can just type in http://localhost ,etc. VERY useful as you can test your code with a simple keyboard shortcut.
That’s it for now! Stay tuned on this page I will go into more PHP programming. Including string and math functions, If, then, else ,etc. And most importantly interfacing with a database (mysql).
Thanks for reading!
This article was viewed (173) times!