Question
What kind of file is php? Which software can be used to open it
Solution
PHP, a nested abbreviation name, is the abbreviation of English Hypertext Preprocessing Language (PHP: Hypertext Preprocessor). PHP is an HTML embedded language. PHP is somewhat similar to Microsoft's ASP. Both are scripting languages that are embedded in HTML documents and are executed on the server side. The style of the language is similar to C language. It is now used by many It is widely used by website programmers. PHP's unique syntax is a mix of C, Java, Perl, and PHP's own innovative syntax. It can execute dynamic web pages faster than CGI or Perl. Compared with other programming languages, dynamic pages made with PHP embed the program into the HTML document for execution, and the execution efficiency is much higher than CGI that completely generates HTML tags; compared with the scripting language JavaScript, which is also embedded in the HTML document In contrast, PHP is executed on the server side, making full use of the server's performance; the PHP execution engine will also store PHP programs that users frequently access in memory, so other users do not need to recompile the program when they access the program again. Just execute the code in the memory directly, which is also one of the manifestations of PHP's high efficiency. PHP has very powerful functions. All CGI or JavaScript functions can be implemented by PHP, and it supports almost all popular databases and operating systems. //PHP open source code
PHP was originally created by Rasmus Lerdorf in 1994. It started as a simple program written in Perl language to count visitors to his own website. Later it was rewritten in C language, including access to the database. The first version was released in 1995 as Personal Home Page Tools (PHP Tools). Lerdorf wrote some documents introducing the program and released PHP 1.0. In this early version, simple functions such as guest book and visitor counter were provided. In the future, more and more websites used PHP, and there was a strong need to add some features, such as loop statements and array variables, etc. After new members joined the development team, PHP 2.0 was released in mid-1995. The second version is named PHP/FI (Form Interpreter). PHP/FI added support for mSQL, and has since established PHP's position in dynamic web development. By the end of 1996, there were 15,000 websites using PHP/FI; by mid-1997, the number of websites using PHP/FI exceeded 50,000. In mid-1997, the development plan for the third version was started. The development team joined Zeev Suraski and Andi Gutmans, and the third version was named PHP3. In 2000, PHP4.0 came out again, which added many new features. sex. //OSPHP.COM.Cn Open Source
PHP features include:
Open Source: Virtually all PHP source code is available.
PHP is free.
Based on the server side: Since PHP is a script that runs on the server side, it can run under UNIX, LINUX, and WINDOWS.
Embed HTML: Because PHP can embed HTML language, it is not difficult to learn.
Simple language: PHP insists on scripting language as the main language, unlike Java, which is C++.
High efficiency: PHP consumes considerably less system resources.
Image Processing: Dynamically Create Images with PHP
Comparison of PHP 3 and PHP 4
PHP3 is closely integrated with the Apache server; coupled with its continuous updates and new features; and its support for almost all mainstream and non-mainstream databases; and its high-speed execution efficiency, PHP has become the most popular site in mid-1999. More than 1,500,000. In addition, its source code is completely open to the public. Today, with the rise of Open Source awareness, it is the mainstay in this regard. The constant addition of new function libraries and the vitality of constant updates enable PHP to have more new functions whether on UNIX, LINUX or Windows platforms. It provides rich functions to provide better support in programming. //PHP open source code
The core of the entire script program in PHP4.0 has been significantly changed to allow the execution speed of the program to meet faster requirements. After optimization, the efficiency is better than that of traditional CGI or ASP programs. There are also stronger new functions and a richer function library. Whether you accept it or not, PHP will set off a revolutionary revolution in the field of Web CGI. For a professional Web Master, it will also be one of the required courses.
PHP 4.0 is a more efficient and reliable dynamic web page development tool that runs faster than PHP 3.0 in most cases. Its script description is more powerful and more complex. The most significant feature is the increase in speed ratio. These excellent performances of PHP 4.0 are the result of the redesign of the PHP script engine: the engine was completely rewritten from the bottom up by AndiGutmans and Zeev Suraski. The PHP 4.0 script engine, the Zend engine, uses a more efficient compile-execute approach, rather than the execute-when-parsed model adopted by PHP 3.0.
PHP4 adds or enhances many useful features based on version 3.0, mainly as follows:
(1) Alias: In PHP4, you can use references to assign values to variables, which brings great flexibility to programming.
//OSPHP.com.CN
(2) Expanded API module: PHP 4.0 provides an extended PHP interface module for the extended API module, which is significantly faster than the old API version. Most of the existing and most commonly used interfaces of PHP modules have been converted to interfaces using this extension.
(3) Automatic resource release: PHP4 adds a reference counting function. The introduction of this new technology enables PHP4 to have automatic memory management functions, reducing the burden on developers.
(4) Boolean type: PHP 4.0 supports Boolean type.
(5) Process generation: PHP 4.0 in the UNIX environment provides a very intelligent and versatile generation process, using a system generation technology based on automake/libtool.
(6) COM/DCOM support: PHP 4.0 provides COM/DCOM support (only for Windows environment), which can seamlessly access and access COM objects.
(7) Very good compatibility with PHP 3.0: PHP 4.0 is nearly 100% backward compatible with PHP 3.0 code. Due to the improved architecture of PHP 4, there are some subtle differences, but most people will probably never encounter this situation.
//OSPHP.com.CN
Introduction to PHP
(8) Configuration: PHP4 redesigns and enhances PHP. ini file, which is made using PHP. ini to configure PHP is extremely easy. This file can be registered by Apache (unix system) or by Windows (Windows environment) at runtime.
(9) Encryption support: PHP4 implements complete encryption, these encryption functions are a complete mycrypt library, and PHP 4.0 supports hash functions. Blowfish, TripleDES, MD5, and SHA1 are also some of the encryption algorithms that can be used.
(10) Type checking: PHP 4.0 supports the same operator for type checking: === (3 equal sign operator), which checks between two values and their types. For example, 3 ===3 will be considered false (the types are different), while 3 ==3 (equality) will be considered true.
(11) FTP support: PHP 4.0 supports FTP. Typically, you would provide an interface for downloading a large file over a modem connection. However, if you really need it, you can use PHP.
(12) New functions or enhanced functions in PHP4: PHP 4.0 has added many new functions and also enhanced many existing functions. Here are some examples. array_count_values() eval() foreach() nclude() ob_end_clean() ob_end_flush() ob_get_contents() ob_start() strip_tags() unset()
//Open source OSPhP.COM.CN
(13) Here printing: PHP 4.0's Here printing is similar to Perl, although completely different. Here is a useful method for printing large-volume articles, such as HTML files, without missing a single character such as a table of contents tag.
(14) HTTP Session fallback system: A fallback system for HTTP Session management is implemented in PHP 4.0. By default, session identifiers are stored in cookies. If there is no cookie support or a cookie task fails, the Session identifier is automatically created and carried in the URL's query string.
(15) ISAPI support: PHP 4.0 can be used as a personalized ISAPI module as an IIS plug-in. This is more efficient than PHP 3.0, which runs as an external program.
(16) Memory: PHP 4.0 can use memory more efficiently, resulting in less memory consumption, mainly due to the implementation of reference counting technology.
(17) Member functions of other classes: In PHP 4.0, you can call member functions of other classes in the scope of the member function itself or in the global scope. For example, you can override a parent function with a child function and call the parent function in the child function. //Open source OSPhP.COM.CN
(18) Multi-dimensional arrays: In PHP 4.0, data transmission using GET, POST, and Cookies supports multi-dimensional arrays.
(19) Personalized HTTP Session support: HTTP Session processing, including fallback system management, is implemented by its new library function in PHP 4.0. Handling Sessions in version 3.0 requires the use of PHPLIB and third-party library functions, which is much slower than having Sessions supported directly by PHP.
(20) Personalized Java support: PHP 4.0 supports interaction with Java. This personalized Java support provides PHP with a simple and efficient tool for creating and using methods on Java objects.
21) Objects and nested groups of numbers: PHP 4.0 implements more powerful objects and removes various syntax restrictions that existed in PHP 3.0. Objects can be nested within arrays and vice versa, depending on your needs.
(22) Object-oriented programming: PHP 4.0 provides extended functionality and new features for object-oriented programming and constructing classes and objects. PHP4 implements new technologies such as object overloading and reference technology.
(23) Object overloading support: Object overloading syntax allows third-party object-oriented class libraries to use the object-oriented features of PHP4 to access their own functions. A COM module using this feature has been implemented.
//PHP open source code
(24) Output buffering support: PHP provides a collection of output buffering functions. Output buffering support allows you to write functions that wrap functions around compressed buffers. Output buffering support in PHP4 allows HTML header information to be stored regardless of whether the HTML body is output. Header information ((header(), content type, and cookies) is not buffered.
(25) Added PCRE library: PHP 4.0 includes a Perl-compatible regular expression (PCRE) library, which is bundled with PHP together with the normal regex library. The split and replace PCRE functions are supported. There are some subtle differences between PCRE and Perl regular expressions.
(26) PHP.ini file: The PHP.ini file was redesigned in PHP4.0, and the configuration of PHP using PHP.ini is easier and more effective. All files can be manipulated by Apache at runtime (under Apache) or by the Windows registry (under Windows). Configuration directives added to the PHP.ini file are automatically supported in all related modules.
(27) Reference counting: PHP 4.0 provides a reference count for every value in the system, including resources. Once a resource is no longer referenced by any variable, it is automatically released to save memory resources. The most obvious example of utilizing this feature is a loop statement built into a SQL query. In PHP 3.0, each time it is recursed, another SQL result set repeatedly applies for memory. The memory occupied by these result sets is not released until the script is executed. //Open source OSPhP.COM.CN
(28) Support for references: The value of a variable can be changed through references.
(29) Runtime binding of functions: The runtime binding feature of PHP 4.0 allows you to call them before they are declared, regardless of whether the declaration is later in the code or at runtime.
(30) Class runtime information: PHP 4.0 supports access to the following class information at runtime: the class name of an object, the class name of an object's parent class, and the name of the object's function.
(31) Server abstraction layer: Provides an enhanced SAPI (server API) interface to support Web servers, which is an integral part of PHP 4.0. This server abstraction layer provides universal WEB server interface support, supports multi-threaded WEB servers, and provides transparent support for most WEB servers, including Apache, IIS (ISAPI), and AOL servers.
(32) Syntax highlight display: PHP 4.0 syntax highlight display allows developers to see the source code instead of the script. This feature is more effective than in PHP 3.0. It runs faster, performs better, and produces more compact HTML code.
//PHP open source code
(33) Changing the value of a variable by reference: PHP 4.0 supports variable assignment by reference. If the value of any one of the two "associated" variables is changed, the value of the other variable will also be changed. This is similar to Pointer types in C.
(34) Variable references in reference strings: PHP 4.0 enhances variable references in reference strings.
PHP's rich support for databases is also one of the reasons why it has become so popular. It supports the following databases or data files:
· Adabas D
· DBA
· dBase
· dbm
· filePro
· Informix
· InterBase
· mSQL
· Microsoft SQL Server
· MySQL
· Solid
· Sybase
· ODBC
· Oracle 8
·Oracle
· PostgreSQL
On the Internet, it also supports quite a few communication protocols, including IMAP and POP3 related to email; network management system SNMP; network news NNTP; account sharing NIS; global information network HTTP and Apache server; directory protocol LDAP and other network related functions.
In addition, web back-end CGI programs written in PHP can be easily ported to different operating systems. For example, if a website is first built on Linux, when the system load is too high, the entire system can be quickly moved to a SUN workstation without recompiling the CGI program. Faced with the rapid development of the Internet, this is the best choice for long-term planning.
//Open source codeOSPHP.COM.Cn
Variable type:
PHP has many kinds of variables; the main ones are these:
- number (integer - example: 32)
- Boolean value (boolean - example: TRUE)
- string (string - example: 'a string of text')
- NULL
- resource
- array (array - example: arrayname[2])
Grammar:
There are three types of syntax:
//comment
/* comment */
# comment
Basic "Control Structures":
* if ... else
if (condition == true) ;
* if ... else then
if (condition == true)
else if (condition2 == true) ;
A PHP example:
echo "hello world";
//OSPHP.COm.CN
?>
Please see:
php official website: [url=http://www.php.net/]Link tag www.php.net[/url]
PHP’s support for object-oriented
Concepts of object-oriented programming:
Different authors may have different opinions, but an OOP language must have the following aspects:
Abstract data types and information encapsulation
Inheritance
Polymorphism
In PHP, encapsulation is completed through classes:
class Something {
// In OOP classes, usually the first character is uppercase
var $x;
function setX($v) {
// Methods start with lowercase words and then use uppercase letters to separate words, such as getValueOfArea()
$this->x=$v;
}
function getX() {
return $this->x;
}
}
Of course, you can define it according to your own preferences, but it is better to maintain a standard, which will be more effective. Data members are defined in the class using "var" declarations. Before data members are assigned a value, they have no type. A data member can be an integer, an array, an associative array, or an object. Methods are defined as functions in a class. When accessing class member variables in a method, you should use $this->name. Otherwise, for a method, it can only be a local variable.
//OSPHP.COM.Cn Open Source
Use the new operator to create an object:
$obj=new Something;
Then you can use member functions via:
$obj->setX(5);
$see=$obj->getX();
In this example, the setX member function assigns 5 to the object's member variable x (not the class), and then getX returns its value 5. You can access data members through class references like: $obj->x=6. This is not a good OOP habit. I strongly recommend accessing member variables through methods. You will be a good OOP programmer if you treat member variables as unmanipulable and use methods only through object handles. Unfortunately, PHP does not support declaring private member variables, so bad code is allowed in PHP. Inheritance is easy to implement in PHP, just use the extend keyword.
class Another extends Something {
var $y;
function setY($v) {
$this->y=$v;
}
function getY() {
return $this->y;
//OSPHP.com.CN
}
}
The object of the "Another" class now has all the data members and methods of the parent class (Something), and also adds its own data members and methods.
You can use
$obj2=new Something;
$obj2->setX(6);
$obj2->setY(7);
PHP currently does not support multiple inheritance, so you cannot derive new classes from two or more classes. You can redefine a method in a derived class. If we redefine the getX method in the "Another" class, we cannot use the getX method in "Something". If you declare a data member in a derived class with the same name as the base class, it will "hide" the base class data member when you deal with it.
You can define constructors in your class. The constructor is a method with the same name as the class name, which is called when you create an object of the class, for example:
class Something {
var $x;
function Something($y) {
$this->x=$y;
//OsPHP.COM.CN
}
function setX($v) {
$this->x=$v;
}
function getX() {
return $this->x;
}
}
So you can create an object via:
$obj=new Something(6);
The constructor will automatically assign 6 to the data variable x. Constructors and methods are normal PHP functions, so you can use default parameters.
function Something($x="3",$y="5")
Then:
$obj=new Something(); // x=3 and y=5
$obj=new Something(8); // x=8 and y=5
$obj=new Something(8,9); // x=8 and y=9
The default parameters use the C++ method, so you cannot ignore the value of Y and give a default parameter to X. The parameters are assigned from left to right. If the parameters passed in are less than the required parameters, the parameters will be used. Default parameters.
When an object of a derived class is created, only its constructor is called, and the constructor of the parent class is not called. If you want to call the constructor of the base class, you must explicitly call it in the constructor of the derived class. This can be done because all methods of the parent class are available in the derived class. //oSPHP.COM.CN
function Another() {
$this->y=5;
$this->Something();
//Display calling base class constructor
}
A good mechanism for OOP is to use abstract classes. Abstract classes cannot be instantiated and can only provide an interface to derived classes. Designers often use abstract classes to force programmers to derive from a base class, thus ensuring that the new class contains some desired functionality. There is no standard method in PHP, but: if you need this feature, you can define a base class and add a "die" call after its constructor, so that the base class is not instantiable. Now Add a "die" statement after each method (interface), so if a programmer does not override the method in a derived class, an error will be raised. And because PHP is untyped, you may need to confirm that an object is a derived class from your base class, then add a method in the base class to specify the identity of the class (return some kind of identification id), and in your Check this value when receiving an object parameter. Of course, if an evil programmer overrides this method in a derived class, this method will not work, but generally the problem is found in lazy programmers, not evil programmers. //OsPHP.COM.CN
Of course, it's nice to be able to keep the base classes invisible to programmers, who can just print out the interfaces and do their job. There is no destructor in PHP.
Overloading (unlike overriding) is not supported in PHP. In OOP, you can overload a method to implement two or more methods with the same name but different numbers or types of parameters (depending on the language). PHP is a loosely typed language, so overloading by type will not work, but overloading by different number of parameters will not work either.
Sometimes it's nice to overload constructors in OOP so that you can create objects in different ways (passing different numbers of arguments). The trick to achieve it in PHP is:
class Myclass {
function Myclass() {
$name="Myclass".func_num_args();
$this->$name();
//Note that $this->name() is generally wrong, but here $name is the name of the method that will be called
}
function Myclass1($x) { //Open source code OSPHP.COM.Cn
code;
}
function Myclass2($x,$y) {
code;
}
}
Using this class is transparent to the user through additional processing in the class:
$obj1=new Myclass('1'); //Myclass1 will be called
$obj2=new Myclass('1','2'); //Myclass2 will be called
Sometimes this is very useful.
Polymorphism
Polymorphism is an ability of an object, which can determine which object method to call based on the passed object parameters at runtime. For example, if you have a figure class, it defines a draw method. And derived the circle and rectangle classes, in the derived class you override the draw method, you may also have a function that expects a parameter x, and can call $x->draw(). If you have polymorphism, which draw method is called depends on the type of object you pass to the function.
Polymorphism is very important in interpreted languages like PHP (imagine a C++ compiler generating code like this, which method should you call? You also don't know what type of object you have, well, that's not the point) Easy and natural. So of course PHP supports polymorphism. //oSPHP.COM.CN
function niceDrawing($x) {
//Assume this is a method of the Board class
$x->draw();
}
$obj=new Circle(3,187);
$obj2=new Rectangle(4,5);
$board->niceDrawing($obj);
//The draw method of Circle will be called
$board->niceDrawing($obj2);
//The draw method of Rectangle will be called
Object-oriented programming with PHP
Some "purists" may say that PHP is not a true object-oriented language, and this is true. PHP is a hybrid language, you can use OOP or traditional procedural programming. However, for larger projects, you may want/need to use pure OOP to declare classes in PHP, and only use objects and classes in your project.
As projects get larger, it may be helpful to use OOP. OOP code is easy to maintain, easy to understand and reuse. These are the foundations of software engineering. Applying these concepts in web-based projects becomes the key to future website success.
//Open source OSPhP.COM.CN
PHP’s advanced OOP technology
After looking at basic OOP concepts, I can show you more advanced techniques:
Serializing
PHP does not support persistent objects. In OOP, a persistent object is an object that can maintain state and functionality among references in multiple applications. This means having the ability to save the object to a file or database, and to load the object later. . This is the so-called serialization mechanism. PHP has a serialization method that can be called on an object, and the serialization method can return a string representation of the object. However, serialization only saves the object's member data and not the methods.
In PHP4, if you serialize the object into the string $s, then release the object, and then deserialize the object into $obj, you can continue to use the object's methods! I don't recommend doing this because (a) there is no guarantee in the documentation that this behavior will still work in future versions. (b) This may lead to a misunderstanding when you save a serialized version to disk and exit the script. When you run this script later, you can't expect that when you deserialize an object, the object's methods will be there, because the string representation doesn't include methods at all. //PHP open source code
In short, serialization in PHP is very useful for saving member variables of objects. (You can also serialize related arrays and arrays into a file).
Example:
$obj=new Classfoo();
$str=serialize($obj);
//Save $str to disk
//A few months later
//Load str
from disk
$obj2=unserialize($str)
You restored the member data, but not the methods (according to the documentation). This results in the only way to access member variables (you have no other way!) by something like using $obj2->x, so don't try it at home.
There are some ways to solve this problem, I left them out because they are too bad for the purpose of this concise article. I would happily welcome fully serialized features in subsequent versions of PHP.
Using Classes for Data Storage One of the great things about PHP and OOP is that you can easily define a class to do something and call the corresponding class whenever you want to use it. Suppose you have an HTML form that allows the user to select a product by selecting the product ID number. There is product information in the database, and you want to display the product, its price, etc. You have different types of products, and the same action can mean different things to different products. For example, displaying a sound might mean playing it, but for other kinds of products it might mean displaying an image stored in a database. You can use OOP or PHP to reduce coding and improve quality: //oSPHP.COM.CN
Define a product class, define the methods it should have (for example: display), and then define a class for each type of product, derived from the product class (SoundItem class, ViewableItem class, etc.), covering the products Methods in classes to make them behave as you want.
Name the class according to the type field of each product in the database. A typical product table may have (id, type, price, description, etc. fields)... Then in the processing script, you can retrieve it from the database Get the type value from , and then instantiate an object named type:
$obj=new $type();
$obj->action();
This is a very good feature of PHP. You can call the display method or other methods of $obj without considering the type of object. Using this technique, you don't need to modify the script to add a new type of object, just a class to handle it.
This function is very powerful. Just define methods without considering the types of all objects, implement them in different classes in different methods, and then use them in the main script for any object, no if...else, no Requires two programmers, only happy.
//Open source code OSPhP.COm.CN
Now you agree that programming is easy, maintenance is cheap, and reusability is true?
If you manage a group of programmers, it is very simple to distribute the work. Each person may be responsible for a type of object and the class that handles it.
Internationalization can be achieved through this technology, just apply the corresponding class according to the language field selected by the user, and so on.
Copy and Clone
When you create an object of $obj, you can copy the object by $obj2=$obj. The new object is a copy (not a reference) of $obj, so it has the state of $obj at that time. Sometimes, you don't want to do this. You just want to generate a new object like the obj class. You can call the constructor of the class by using the new statement. This can also be achieved in PHP through serialization and a base class, but all other classes must be derived from the base class.
Entering the dangerous area
When you serialize an object, you get a string in some format, which you can interrogate if you're interested, where the string has the name of the class in it (great!) and you can pull it out. , like:
//OSPHP.com.CN
$herring=serialize($obj);
$vec=explode(':',$herring);
$nam=str_replace(""",'',$vec[2]);
So assuming you create a "Universe" class and force all classes to extend from universe, you can define a clone method in universe, as follows:
class Universe {
function clone() {
$herring=serialize($this);
$vec=explode(':',$herring);
$nam=str_replace(""",'',$vec[2]);
$ret=new $nam;
return $ret;
}
}
//Then
$obj=new Something();
//Extend from Universe
$other=$obj->clone();
What you get is a new Something class object, which is the same as the object created by using the new method and calling the constructor. I don't know if this will work for you, but it's a good rule of thumb that the universe class knows the name of the derived class. Imagination is the only limit.
Reference answer
Haha··Happy New Year··
Very helpful...hehehe...
Support you·
Reference answer
Basic enough~[img]http://www.111cn.cn/bbs/images/smilies/default/funk.gif[/img]
Reference answer
hehe. . . For newbies. . Very comprehensive! ! ! !
Reference answer
Let’s talk about the basics. . . Finally, serialization was mentioned. . .
Reference answer
It seems very watery.
Reference answer
Too watery. .