PHP Code

What is PHP?

PHP (recursive acronym for PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Nice, but what does that mean? An example:

Example #1 An introductory example

Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages contain HTML with embedded code that does «something» (in this case, output «Hi, I’m a PHP script!»). The PHP code is enclosed in special start and end processing instructions that allow you to jump into and out of «PHP mode.»

What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. You can even configure your web server to process all your HTML files with PHP, and then there’s really no way that users can tell what you have up your sleeve.

The best part about using PHP is that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don’t be afraid to read the long list of PHP’s features. You can jump in, in a short time, and start writing simple scripts in a few hours.

Читайте также:  Html items side by side

Although PHP’s development is focused on server-side scripting, you can do much more with it. Read on, and see more in the What can PHP do? section, or go right to the introductory tutorial if you are only interested in web programming.

User Contributed Notes

Источник

Description of php language

PHP stands for Hypertext Processor and is a very powerful, open-source and popular server-side scripting language that is used by developers to create dynamic and interactive web pages. The programming language allows developers to form content that can interact with different databases and is used to develop web-based software applications. The popular programming language is used by the tech giants like Google, Facebook and Yahoo and can be embedded into other front-end technologies like HTML.

Prerequisites to Learn PHP

There is no rule of thumb as to what one should already know before learning PHP. It is advisable to have a basic understanding of the front-end technologies like HTML and CSS in order in order to offer a seamless user experience on a responsive platform. Since PHP serves to establish a connection between content and database, an understanding of the database management system and software like MySQL will also useful.

Even though it is totally optional, a proper understanding of the programming languages like Java, C and C++ can accelerate the process of learning PHP. PHP has the functional units like loops and arrays and thus having even a basic knowledge of the programming languages will obviously help.

Uses of PHP

PHP is a very powerful and a very versatile programming language that can serve a lot of different purposes.

Server-side Scripting: This is the main function of PHP and a developer needs three things to perform it. The developer needs a one PHP parser to convert a human-readable language to a computer-readable form, a web server to execute the files forming the web pages and a web browser to exhibit content or access the program output.

Command-line Scripting: You can execute or run a PHP script without a web browser or a web server and using just a PHP parser. This function of PHP is normally used for simpler text processing tasks.

Desktop Application Development: Another function of PHP is to create client-side applications. Such applications typically have graphical user interfaces. Advanced PHP features can be used to develop such applications.

Graphic Design and Image Processing: PHP scripts are also used for manipulating image content along with text content. Different image processing libraries like ImageMagick, GD Library and Imagine can be integrated into PHP applications that can then manipulate the images.

Characteristics of PHP

PHP is one of the most widely used server-side scripting languages because of the efficient, quick and practical nature of its services.

  • Open Source: Unlike many programming languages, this is an open-source language that can be redistributed and modified freely.
  • Cross Platform: PHP is compatible with all leading web browsers and operating systems like Linux, Unix, MAC OS, Windows, Solaris. This feature of the software easy deployment of various applications across different browsers and operating systems.
  • Fast Performance: PHP scripts can be executed much faster than the ones written in any other scripting language such as JSP or ASP.NET.
  • Simple, Interpreted and Efficient: PHP is very easy to use and even beginners do not need much time to get the hang of it. PHP is an interpreted programming language that does not require compilation. PHP is efficient enough to be used in a multiuser environment. It supports object-oriented programming, has specific features for session management and reference counting and others.

What is a PHP shell?

PHP Shell is a script or program written in PHP (Php Hypertext Preprocessor) which provides us with Linux Terminal (Shell is a vast concept) in Browser. PHP Shell allows user to execute most of the shell commands in browser, some cannot be executed due to PHP limitations.

Basic PHP Syntax

We can insert PHP script or code anywhere in the document. A PHP script or code starts with :

For Example (PHP Hello World):

Источник

What is PHP? The PHP Programming Language Meaning Explained

Kolade Chris

Kolade Chris

What is PHP? The PHP Programming Language Meaning Explained

PHP is an open-source server-side scripting language that many devs use for web development. It is also a general-purpose language that you can use to make lots of projects, including Graphical User Interfaces (GUIs).

In this article, I will help you explore the world of PHP so you can learn how it works and its basic features. By the end, you will be able to write your first Hello World program in PHP.

What Does PHP Mean?

The abbreviation PHP initially stood for Personal Homepage. But now it is a recursive acronym for Hypertext Preprocessor. (It’s recursive in the sense that the first word itself is an abbreviation, so the full meaning doesn’t follow the abbreviation.)

The first version of PHP was launched 26 years ago. Now it’s on version 8, released in November 2020, but version 7 remains the most widely used.

PHP runs on the Zend engine, which is the most popular implementation. There are some other implementations as well, like parrot, HPVM (Hip Hop Virtual Machine), and Hip Hop, created by Facebook.

PHP is mostly used for making web servers. It runs on the browser and is also capable of running in the command line. So, if you don’t feel like showing your code output in the browser, you can show it in the terminal.

Advantages of PHP

PHP has some advantages that have made it so popular, and it’s been the go-to language for web servers for more than 15 years now. Here are some of PHP’s benefits:

  • Cross-Platform: PHP is platform-independent. You don’t have to have a particular OS to use it because it runs on every platform, whether it’s Mac, Windows, or Linux.
  • Open Source: PHP is open source. The original code is made available to everyone who wants to build upon it. This is one of the reasons why one of its frameworks, Laravel, is so popular.
  • Easy to learn: PHP is not hard to learn for absolute beginners. You can pick it up pretty if you already have programming knowledge.
  • PHP syncs with all Databases: You can easily connect PHP to all Databases, relational and non-relational. So it can connect in no time to MySQL, Postgress, MongoDB, or any other database.
  • Supportive Community: PHP has a very supportive online community. The official documentation provides guides on how to use the features and you can easily get your problem fixed while stuck.

Who Uses PHP

A number of established companies and tech giants use PHP to run their servers and make a lot of incredible things.

  • Facebook: Facebook uses PHP to power its site. In turn, the company contributed to the community by creating an implementation known as Hip Hop for PHP.
  • Wikipedia: one of the world’s largest sources of information on any topic, Wikipedia is built in PHP.
  • Content Management Systems (CMSs): the world’s most popular content management system, WordPress, is built in PHP. Other content management systems such as Drupal, Joomla, and Magento are also built in PHP. Shopify runs on PHP too.
  • Web Hosting Platforms: a lot of Web Hosting Platforms such as BlueHost, Site ground, and Whogohost run their hosting servers using PHP.

Is PHP Dying?

Nowadays, there’s an intense debate on whether PHP is on the decline or not. This is because of the advent and increasing popularity of other languages suited for the server-side such as JavaScript (Node JS), Python, Golang, and others.

php-meme

This has actually led to a lot of funny memes targeting PHP

But is PHP really dying? The answer is no. Despite some people bashing on it and the claims of decline, PHP is still used to run the servers of almost 80% of all websites today. So, if you visit 10 websites a day, there’s a chance that 8 of them use PHP.

In terms of job availability, PHP ranks better than a lot of other programming languages on the job platform Indeed. A lot of PHP developers make a good living making WordPress themes and plugins every year – the average PHP developer in the US makes $86,000 per year.

php-jobs

How to Write Your First Hello World Program in PHP

Now that you have learned about PHP and its advantages, it’s time to write your first Hello World program in it!

First of all, you must have PHP installed on your local machine. You can get that done by installing an XAMP (Cross-Platform, Apache, MySQL, and PHP) or WAMP (Windows, Apache, MySQL, and PHP) server.

XAMP works on all operating systems and WAMP works only in Windows. I will be using WAMP.

Open up the WAMP or XAMP server and make sure all services are running. If you are using WAMP, the WAMP logo should show on your taskbar with the color green.

wamp-running

Open up your C drive and look for the installation directory of your WAMP server. In my case, it is wamp64 .

wampfolder

Open the installation directory, and then the www folder.

wwwfolder

Create a folder right there and name it whatever you want, then open up the folder with your code editor.

Create an index.php file and paste in the following code:

You can also put your “Hello World” text in a variable, then use the echo system to display it in the browser.

In PHP, you can declare a variable with the dollar sign ($). Your statements, apart from the last one, must also be terminated by a semi-colon.

To run your code in the browser, open up the browser and write this in the address bar localhost/the-folder-of-your-php-file/php-file.php , then hit enter.

Make sure your WAMP or XAMP server is running, otherwise it won’t work.

hello-world

You can see that the code successfully ran in the browser, because I got the file path right.

Another beautiful thing about PHP is that you can embed it in HTML. You can do it like this:

         

This is the result of a PHP Code embedded in HTML

"; echo $campers ?>

php-in-html

Conclusion

PHP remains a relevant and widely-used language in web development. Despite the mockery and debate on whether it’s still valuable, PHP developers keep earning good livings from working with the language. So, PHP doesn’t seem to be going anywhere anytime soon.

Thank you for reading, and keep coding.

Источник

Оцените статью