“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens
There’s a passionate community of people who code in PHP. Millions of people use this programming language to create web sites or other web pages. Programming has never been so accessible.
Like some other programming languages (HTML, CSS, Java, MySQL, etc.), PHP can be used in the creation of web sites.
Managing databases, graphic interfaces, web servers, IT systems, you don’t need to be an IT engineer to start learning how to code with PHP.
In this article, we'll look what PHP is, how you can use it to display images, how to open a PHP file in your web browser, and which version you should use with WordPress, the world's most popular content management system.
What Is PHP?
IT is taught in schools and the younger generation learn how to use computers, but they don’t necessarily want to create IT technicians. You can get into PHP in just a few hours.
So what is PHP script?
PHP is a programming language that’s mainly used for creating web pages. It’s an open-source language, meaning that anyone can access it.
The language was invented in 1994 by Rasmus Lerdorf. He wanted to know how many people were visiting his website. After this, amateur coders started using the language and it started to change. Numerous featured were developed.
Managing databases, HTML, development environment, scripts, command lines, managing servers, etc. PHP has plenty for amateurs to sink their teeth into.
PHP can be used to make dynamic web pages. Unlike static web pages that display the same page automatically, dynamic web pages display differently depending on the user. This language allows to create member pages for subscribers, etc.
PHP can work on any operating system (Microsoft Windows, Mac, Linux, Unix, etc.). It’s used by web developers to code websites, generate PHP images, text, PDF files, etc. It can also be used by amateur developers. Its ease-of-use is both an advantage and a disadvantage. A lot of users can create interesting web pages but also ones with errors.
It’s easy to learn PHP, but it’s much harder to avoid errors. PHP can save you a lot of time by replacing HTML code with lines of PHP code. Furthermore, thanks to the PHP community, it’s very easy to find advice and tips. There are plenty of big businesses that use PHP for their websites.
Learning to programme is an advantage. There has never been so many people working with digital technologies. With analysts, programmers, PHP developers, app developers, web technology specialists, web developers, etc., knowing how to code is an important skill. For web development, app development, etc, IT training is a good way to learn the basics. A programming class could help you to code in PHP and learn common expressions and syntax.
Find out why you should use PHP.
How Do You Display an Image in PHP?
PHP comes with a number of different features. While it’s usually used to create web pages via HTML, you can also code images, text, etc.
You can integrate an image into a web page, but how?
Tags, hosting, resizing an image, if you want to start working with PHP, there are a few things you’ll need to learn about. Firstly, you need to tell the server that the element isn’t a web page but an image so you’ll need to indicate this in the header.
The header function will do the trick. By typing “header” at the start of the code, the server will know that it’s dealing with an image. Unfortunately, “header” won’t be enough. You’ll also need to add: “Content-type: image/jpeg”.
In this case, the image is a jpeg, but you can also use formats like png. You just need to replace the letters at the end.
This line of code isn’t enough to let the server know which image you’re dealing with.
You’ll need a second line of code. The function “imagecreatefromjpg” or “imagecreatefrompng” needs to be followed by the name of the image you’ve saved. You’ll also need to indicate some variability with this line: “$image =”. Thus, you’re indicating that the image can change.
Finally, to display the image on the website, you’ll need to let the server know what you want. To do this, the line needs to include “imagejpg” or “imagepng”.
Here’s an example of the lines of code you’ll need to write.
header (“Content-type: image/jpeg”);
$image = imagecreatefromjpeg(“myphoto.jpg”);
If you don’t want to display the image directly on the website, but keep it as it is in a file, the last line needs to be replaced by the filename of the photo plus the destination.
Your photo is ready!
How to Open a PHP File in Your Browser
Before you can start getting the most out of your dynamic website, there are a few steps you’ll need to follow. To put the code together, you’ll need to download a PHP engine for your site. You’ll need to download the engine onto your computer, install it, then install an editor specific to the programming language. You can use programmes like Notepad++, Dreamweaver, etc.
In a word processor, you can write lines to make dynamic web pages.
Once your sheet of code is ready, you’ll need to test your PHP file online. This step allows you to check for errors and see if elements are displaying as you intended.
To read a PHP file online, there are a few options. The best solution is to rent a server and put your code on it. A server is a computer that allows other users to access it on the internet via an IP address.
Renting a server is very easy. There are many sites where you can rent a server with a monthly subscription.
Once you’re renting a server, you just need to download your PHP file to it, then type the appropriate address into your browser.
The second option doesn’t include renting a server. If you’re not ready to publish your page, you can download the programme XAMPP. This allows you to imitate a server with a “localhost” address.
Once the programme’s installed, you just have to integrate the PHP files into the app and the put address into your browser.
Which Version of PHP Should You Use for WordPress?
WordPress is a CMS (Content Management System) which allows a lot of people to create a website without knowing about web programming. Be it a blog, website, portfolio, etc, there are plenty of themes allowing to personalise your content. Of course, these options aren’t always enough for users so you can modify the base code as well.
Find different computer science classes for your kids.
WordPress uses the PHP language. You can introduce lines of PHP code into the site and add plugins.
So which version of PHP should you use?
There are plenty of versions of PHP and they continue to evolve. The latest version of PHP is 7 and improvements are regularly being made.
It’s strongly recommended by WordPress that you use the latest version for both its functionality and security. To change your version, the SG Optimizer plugin can help.
To do this, you need to update the theme and plugins in your site so that they’re compatible with the latest version of PHP to avoid bugs and errors.
Updating to the latest version of PHP once a year is a good way to ensure that your website works well. Think about it!
If you want to learn more about programming in PHP, consider getting in touch with a private tutor. There are three types of tutorials offered on Superprof: face-to-face tutorials, online tutorials, and group tutorials.
Face-to-face tutorials are your traditional private tutorials with one student and one tutor. These are usually the most costly but they're also the most cost-effective as the tutor can spend the whole time focusing on their only student.
Online tutorials are similar to face-to-face tutorials but the tutor delivers the class over webcam using video conferencing software like Skype. This tends to be cheaper since they don't have to travel.
Group tutorials are cheaper per student since the cost is shared but you won't get as much individual attention from your tutor as they'll have other students to pay attention to during the tutorials.
Don't forget that a lot of the tutors on Superprof offer the first hour of tutoring for free so you can see if they're right for you.
The platform that connects tutors and students