PHP Code

What can PHP do?

Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.

  • Server-side scripting. This is the most traditional and main target field for PHP. You need three things to make this work: the PHP parser (CGI or server module), a web server and a web browser. You need to run the web server, with a connected PHP installation. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming. See the installation instructions section for more information.
  • Command line scripting. You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on *nix or Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks. See the section about Command line usage of PHP for more information.
  • Writing desktop applications. PHP is probably not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way. PHP-GTK is an extension to PHP, not available in the main distribution. If you are interested in PHP-GTK, visit » its own website.

PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, macOS, RISC OS, and probably others. PHP also has support for most of the web servers today. This includes Apache, IIS, and many others. And this includes any web server that can utilize the FastCGI PHP binary, like lighttpd and nginx. PHP works as either a module, or as a CGI processor.

So with PHP, you have the freedom of choosing an operating system and a web server. Furthermore, you also have the choice of using procedural programming or object-oriented programming (OOP), or a mixture of them both.

With PHP you are not limited to output HTML. PHP’s abilities includes outputting images, PDF files and even Flash movies (using libswf and Ming) generated on the fly. You can also output easily any text, such as XHTML and any other XML file. PHP can autogenerate these files, and save them in the file system, instead of printing it out, forming a server-side cache for your dynamic content.

One of the strongest and most significant features in PHP is its support for a wide range of databases. Writing a database-enabled web page is incredibly simple using one of the database specific extensions (e.g., for mysql), or using an abstraction layer like PDO, or connect to any database supporting the Open Database Connection standard via the ODBC extension. Other databases may utilize cURL or sockets, like CouchDB.

Читайте также:  Проверить какая версия php

PHP also has support for talking to other services using protocols such as LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You can also open raw network sockets and interact using any other protocol. PHP has support for the WDDX complex data exchange between virtually all Web programming languages. Talking about interconnection, PHP has support for instantiation of Java objects and using them transparently as PHP objects.

PHP has useful text processing features, which includes the Perl compatible regular expressions (PCRE), and many extensions and tools to parse and access XML documents. PHP standardizes all of the XML extensions on the solid base of libxml2, and extends the feature set adding SimpleXML, XMLReader and XMLWriter support.

And many other interesting extensions exist, which are categorized both alphabetically and by category. And there are additional PECL extensions that may or may not be documented within the PHP manual itself, like » XDebug.

As you can see this page is not enough to list all the features and benefits PHP can offer. Read on in the sections about installing PHP, and see the function reference part for explanation of the extensions mentioned here.

Источник

6 Useful Things To Do With PHP

PHP Code

Angela Bradley is a web designer and programming expert with over 15 years of experience. An expert in iOS software design and development, she specializes in building technical hybrid platforms.

PHP is a server-side programming language that is used in conjunction with HTML to enhance the features of a website. So what can you do with PHP? Here are 10 fun and useful things you can use PHP for on your website.

Have a Member Log In

You can use PHP to create a special area of your website for members. You can allow users to register and then use the registration information to log in to your site. All of the users’ information is stored in a MySQL Database with encrypted passwords.

Create a Calendar

You can use PHP to find today’s date and then build a calendar for the month. You can also generate a calendar around a specified date. A calendar can be used as a standalone script or incorporated into other scripts where dates are important.

Last Visited

Tell users the last time they visited your website. PHP can do this by storing a cookie in the user’s browser. When they come back, you can read the cookie and remind them that the last time they visited was two weeks ago.

Redirect Users

Whether you want to redirect users from an old page on your site that no longer exists to a new page on your site, or you want to give them a shorter URL to remember, PHP can be used to redirect users. All of the redirection information is done server side, so it is smoother than redirecting with HTML.

Add a Poll

Use PHP to let your visitors take part in a poll. You can also use the GD Library with PHP to display the results of your poll visually instead of just listing the results in text.

Template Your Site

If you like to redesign the look of your site often or want to keep the content fresh on all the pages, then this is for you. By keeping all of the design code for your site in separate files, you can have your PHP files access the same design. This means when you make a change, you only need to update one file and all your pages change.

Читайте также:  Test method throws exception java

Источник

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.
Читайте также:  Python tasks in parallel

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.

Источник

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