[PHP] PHP technical basics

Source: Internet
Author: User
Tags pear drupal
Document directory
  • Origin
  • Basic PHP syntax impressions
  • Quick Overview of PHP Technology
Origin

I have been using the PHP language for many years. In the past few years, although I have not used PHP to develop any large projects, I have been using PHP for some small projects and paying attention to the development of PHP. Why is the PHP language so interesting to me? There are two reasons:

  • PHP is an open-source language, and its language and library are both open-source. It also has a mature open-source community, which is a great support for technical developers;
  • PHP is a completely Web-oriented language. PHP's focus on Web development gives it some incomparable advantages over other languages in Web development. For example, PHP can not only write a Web site with a feather level, but also support large-scale Web applications with ultra-load. PHP has many clear and concise solutions on the Web, which are incomparable to many common languages. For example, Python, another open-source language I like, can also be used to develop Web applications. However, the goal of Python is obviously not limited to Web development. Therefore, Python is not more productive than PHP in Web development.

Although the above are some personal opinions, PHP is obviously the most popular language in practical applications. Many well-known websites are built on PHP.

The web development I have experienced over the past few years is still concentrated on the. NET platform. So for PHP, it is only personal care, and there are not many practical projects. However, since the beginning of this year, with the development of open-source software, there have been more projects using PHP on the Web end. Several of my friends are developing PHP projects, which were hard to see a few years ago. I am very happy to see this change. The development of open source is bound to profoundly affect the development of the software industry, so that more and more software resources will be produced, and we will not face the "Wintel" World, this is good ......

So I sorted out some of my PHP technical notes over the years and put them on the road of self-web development. Before the stone, I was a bit of PHP enthusiast. After the stone, I will explore PHP technology more deeply and work in the PHP world.

Basic PHP syntax impressions

PHP is an application-oriented language. It gets inspiration from multiple languages and contains many language traits. Therefore, PHP is a good language for anyone familiar with C, C ++, Java, and other languages. In addition, it adopts the most direct embedding method -- . This embedding method maximizes its contact with HTML and XHTML, which is extremely cost-effective from the engineering point of view. For this reason, after the emergence of PHP, Ms can introduce this method into IIS to develop the ASP language.

Of course, there are also many problems with the direct embedding method. The most important thing is that it cannot be bigger. The homepage is good, but it is difficult for multiple teams to operate web applications. PHP draws on the include method from C/C ++, based onInclude,Require,Require_onceKeywords for multi-document Association. In PHP4/5, the separation between the front and back ends is emphasized, and the Web program is built using the MVC design mode. After years of development, the PHP language has been competent for the development of large-scale Web programs.

I think the core of PHP should be:

  • Library and framework: References the experience in C/C ++. Library learning is the core of PHP. PHP has two class libraries: Core and extended libraries ). String operations, Array Operations, date operations, and regular expression operations should be carefully performed in the core library. Many of these libraries are based on the Web UI, the input and output of Web programs are critical technologies that involve many security and stability issues and user experience issues. The extended library is convenient for development. PHP has a wealth of extended library resources. Whether it is PECL expansion or PEAR expansion, or many PHP program modules on sf.net, it can be used for reference. Some mature libraries or programs have become a stable framework, such as Smarty and Drupal. Using these frameworks can greatly improve the speed and quality of project development. reading these frameworks can greatly improve the skill of Self-PHP. It is most worthwhile to spend time and effort on Libraries and frameworks.
  • OOP Development and Design Model: Although the OOP design is not supported until PhP5, "callback function" can be used in PhP4 to simulate the dynamic model of the class. Now, oop development has become a basic technology. Whether it is a large project program with many people or a small program with single users, we should adopt oop. The simplest callback function in PHP is a function variable, as shown in the following figure.
 
Quick Overview of PHP Technology

I have sorted out some of the PHP technologies accumulated over the past few years. They mainly include:

  • String Library: Similar string processing function libraries are available in Java and. net. Note that the mbstring extended library of the Unicode Character Processing library is used;
  • Array Processing: Unlike C/C ++, PHP array processing technology is very complex and closely related to page efficiency. For example, use shuffle () or array_rand () to randomly extract elements. Use foreach instead of for to traverse arrays. More importantly, PHP arrays play the role of configuration objects and storage objects. Before using many libraries or frameworks, you must set a configuration array for custom configuration;
  • Date and Time: Pay attention to the location where it is applicable. It is not necessary to detail its data in milliseconds. Its efficiency may be related to the server and network environment. Therefore, for PHP program testing, the client-side JavaScript should be used for timing, which is more useful than the PHP server-side timing;
  • Regular Expressions and server Variables: In PHP, regular expressions and server variables are the most basic tools used to prevent attacks and filter and verify HTTP access. Before development, I developed a myfilter class based on regular expressions and server variables. This class is used to filter information and implement the most basic protection functions;
  • Database: You need to thoroughly study the data abstraction layer technology and have a full understanding of metabase/pear: DB/PDO, ADODB, and other abstraction layer libraries. In this way, the database program can be well transplanted. I chose ADODB mainly because it is similar to the. NET architecture and supports python.
  • Session management: In the web2 environment, Cookie management is more important than session management. For core business steps in the PHP project, session management is not implemented using Ajax. For other non-core services (mainly queries), Cookie management can be used, sending some javascript programs to cookies is very helpful for improving the customer experience.
  • Internationalization and Localization: PHP projects should adhere to the use of Utf-8 coding (pages and data), and programming UI, should use the gettext extension library for multi-language support. My practice is to develop PHP Based on the Drupal framework and make full use of the t function method provided by Drupal for internationalization and localization.
  • Cache and Encryption: PHP has good caching and encryption technologies. Relevant libraries include ob _ Library, MD5, SHA1, Cracklib extension library, and mycrypt extension library. The cache and encryption technology can effectively improve system performance, especially in core data processing. In terms of user experience, my focus is on the combination of Ajax technology and Xml;
  • Other technologies: PHP Shell technology can be used to automate some system services. The Curl library can be used to create some automatic crawler programs for unit testing and data mining; PHP has good technical solutions for image processing. GD2, Ming and ImageMagick are both good choices.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.