Are you interested in learning how to code PHP scripts? It’s very interesting and rewarding. Besides, half of the servers on the internet use PHP, so it’s a wise choice.
What is PHP?
PHP is a scripting language developed by Rasmus Lerdorf. He created PHP back in the 1990s to compete with HTML web pages. He soon discovered there was much more PHP could do and bridges HTML and database functionality. Your HTML web pages cannot login people with an account easily without the help of PHP. To read more about PHP, go straight to the source, the PHP home page.
Where is PHP?
Well, it’s just about everywhere you go on the internet. Facebook is mostly PHP, WordPress is written in PHP, most websites that are database-driven are usually PHP. It’s being used heavily and it is a hot language to learn. Let’s see some PHP in action.
Create a PHP file
You will have to install PHP onto your server or workstation. I install it onto Linux LAMP servers where I will be running web sites, but you could install it onto your Windows machine using WAMP, or onto a MAC using MAMP. It is beyond the scope of this post to install and configure LAMP, MAMP or WAMP. Perhaps another post if anyone is interested. Comment below you want to see that and I will get on it for you!
Assuming you have a *AMP server already setup, you would navigate to a web server you have already created and confirmed working, then create the following file: hello.php Normally you would use an IDE (integrated Developers Environment) but you could use most text editors to create a simple PHP file. Here are directions if you are confused:
Navigate to a web directory on your web server
Create a file called hello.php. If you already have a file called hello.php, use a different file name.
Open the hello.php file and insert this code:
NOTE – the closing ?> is not necessary if you end this file with PHP and have no other languages like HTML following it.
Now save what you typed or copied in, usually with CONTROL+S or SAVE from your menu.
That’s all there is to a basic PHP script.
Explain The PHP Script
Let me explain the above PHP script. First, you created a file called hello.php. It was empty but you typed or copied in the code I showed you. Then you saved it so you would not lose it.
The very first line of a PHP script must contain the characters <?php and it must be fully left justified. Make sure there are no spaces before the <?php or the script may not run, and if it does, it will be flaky.
I added a few empty lines for space to help readability. You could take out the space and just add code to every line if you so desired. For short scripts, I often use space for readability, but long 500-liners, I take out a lot of space or I would scroll for eternity while working or troubleshooting the code.
The first stanza after my <?php declaration is echo ‘Hello’;. Echo is the command followed by two apostrophes, often called single ticks. You can also use the quote symbol, “ which is often called double-ticks. These are iterators that will display any text that is in between them. In this case, Hello would be displayed. The major difference between single tick and double-ticks is this:
Single ticks – will display exactly what you wrote and will not resolve variables.
Double-ticks – will display everything you wrote plus it will resolve all variables you included.
I closed the script with ?>. Note that you do not have to end the script with the ?> if there is nothing else in the file, but if you were going to continue the file with perhaps some HTML close, then you would need to code ?> to tell the code this is the end of PHP so that some other code could be inserted next.
Run Your PHP Script
Place your PHP scripts in any directory under a website you have created, then point your browser at the file, for example, type thsi into your browser:
You should see Hello displayed in an all white screen. The HTML designed in you would now doctor that up into something pretty, but before you go that far, you got the test a short PHP script to see it work.
After that the sky is the limit. You will want to learn about variables, functions, classes, and so much more than I can put in this post. But I will be expanding on this for people who wish to learn more about coding PHP! Just follow the blog and comment so I know you are interested.
There is a new Firefox in town and it’s called Firefox Quantum. It looks like chrome with Apple iPad colors. They moved some menus around, but it is really fast as promised. Many of your favorite plugins may no longer work until the devs play catch-up. Mozilla, the authors of Firefox, discovered many of these addons bypass their code isolation, which created vulnerabilities through which hackers could attack you. These doors have been closed with Quantum.
The Open Menu has changed and will take your eye a little while to find all your familiar selections. For example Add-ons, Options, and Customize no longer have big icons on the old menu, it’s in the middle of the pull-down list you get.
The browser’s autoscroll feature, as well as scrolling by keyboard input and touch-dragging of scrollbars, now use asynchronous scrolling. These scrolling methods are now similar to other input methods like mousewheel, and provide a smoother scrolling experience
Middle mouse paste in the content area no longer navigates to URLs by default on Unix systems
Removed the toolbar Share button. If you relied on this feature, you can install the Share Backported extension instead.
Some older versions of the ATOK IME, including ATOK 2006, 2008, 2009 and 2010, can cause crashes and are therefore disabled on the Windows 64-bit version of Firefox Quantum. To fix those incompatibility issues, please use a newer version of ATOK or one of other IMEs.
The default font for Japanese text is now Meiryo
Complete visual refresh of both the Light and Dark DevTools themes, matching the new visual style of Firefox Quantum
The Inspector shows the values of CSS variables on hover
Completely new and re-designed Console panel. Joining the Debugger and the Network Monitor, the Console has been rewritten using modern web technologies such as React and Redux. It now also allows to inspect objects in context.
Users running Firefox for Windows over a Remote Desktop Connection (RDP) may find that audio playback is disabled due to increased security restrictions. Learn how to mitigate this issue until it is corrected in an upcoming release
Users running screen readers may experience performance issues and are advised to use Firefox ESR until performance issues are resolved in an upcoming future release
On Windows and Linux, Firefox crashes occasionally on Intel Broadwell-U processors with old microcode. Windows users should ensure Windows Update is set to install updates. Linux users should ensure that the distribution package for Intel microcode is installed.
When you first install WordPress, you can create posts and web pages. Web pages can be selected from your website main menu (or some other menu you may decide to create) and are displayed in a standard document format. Posts are very similar but they are pushed down in your blog view as you create new posts. However, WordPress does not give you a menu item to select Blog like it does a standard web page. The WordPress devs assume the user will simply click your logo or title, which would take them to the blog. But what if you wanted a menu item anyway? Or suppose you went into the configs and select Display Web Page rather than Display Latest Post? How would the users easily find your posts? Well, here is the answer, and it’s really simple.
First, make a page called Blog.
Make sure the new Blog page got added to your Main Menu
Navigate to your website and you should now see Blog as a select-able web page.
…and that’s all there is to it. The solution is practically obvious, but if you were like me, it left you scratching your head in wonder for a little while. I hope that helps you and if it does, please comment below!
Note that this template is the default as specified by current HTML5 standards, but includes a few extra <meta> tags in the <head> element.
These metadata elements are not absolutely necessary, but the description, keywords and author meta tags will help your web site rank higher in search engines, and conversely…lose rank if they are not present. They are providing the search engines basic descriptions about your website which in turn helps users looking for subjects your website contains. The last <meta> tag “viewport” helps define your view port scaling dimensions in various browsers and is highly recommended. The <meta> tags will not show up in the web document, so don’t worry – your users will not see them. However search engines will parse the metadata, which again will help your SEO rank.