返回介绍

PHP

发布于 2025-02-22 22:19:59 字数 3674 浏览 0 评论 0 收藏 0

In this part of the PHP tutorial, we talk about the PHP programming language in general.

Goal

The goal of this tutorial is to get you started with the PHP programming language. The tutorial covers the core of the PHP language: variables, arrays, control structures, and other core features. It does not cover web development, databases, or other numerous topics. In this tutorial, we cover PHP 5.6.

PHP

PHP is a scripting language designed for web development. It is used to produce dynamic web pages. Currently, PHP is one of the most widely used programming languages. Much of its syntax is borrowed from C, Java, and Perl with a couple of unique PHP-specific features. PHP can be embedded into HTML code and it generally runs on a web server. The web server needs to be configured to process PHP code and create web page content from it. It can be deployed on most web servers and operating systems. PHP is a free software. PHP was first created in 1995 and is actively developed since then. Today, there are two main branches of PHP: PHP 5 and PHP 7.

PHP supports both object oriented and procedural programming styles.

The official web site for the PHP programming language is php.net

Installing PHP

We download PHP from the http://php.net/downloads.php page. We have downloaded php-5.6.17.tar.bz2 file.

$ bunzip2 php-5.6.17.tar.bz2
$ tar -xf php-5.6.17.tar
$ cd php-5.6.17/

We decompress the file and move into the build directory.

$ sudo apt-get install libreadline-dev

We need to install readline development library for PHP interactive shell.

$ ./configure --with-readline

We run the configure script with readline support enabled.

$ make
$ sudo make install

We build and install PHP. It is possible that we need to install some additional packages. For instance, the author had to install libxml2-dev library.

$ php -a
Interactive mode enabled

php > echo phpversion();
5.6.17

We run PHP in interactive mode and get the version of PHP.

Another option is to install PHP from packages.

$ sudo apt-get install php5-cli

We install the php5-cli module (Debian-based Linux). Note that packages are usually older that the latest versions of the software. When we install PHP from the sources, the php5-cli module is included by default.

PHP CLI

PHP CLI is a command line interpreter for the PHP language. It is useful for testing PHP scripts from the shell. In this tutorial, we are using the PHP command line interpreter. We focus on the core of the PHP language.

simple.php

<?php

echo "this is PHP language\n";

?>

Here we have a simple PHP script.

$ php simple.php
this is PHP language

We execute the script.

Interactive shell

Like Python or Ruby, PHP also has an interactive shell. It is useful to test small language constructs.

$ php -a
Interactive mode enabled

php > print PHP_OS;
Linux
php > print PHP_VERSION;
5.6.17

The PHP shell is invoked with the -a option of the php command. The shell uses the php > prompt.

References

In this part of the PHP tutorial, we have introduced the PHP language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文