Getting Started with PHP - PHP Manual Notes
I once briefly learned PHP by reading "PHP and MySQL Web Development" and with the help of a universal search engine. This time I am going to study the system. The reference material is PHP Manual.
What PHP can do
PHP is mainly used for server-side script programs, but the functions of PHP are far from limited to this. PHP is mainly used in the following three areas:
Server scripts
Command line scripts
Writing desktop applications (PHP-GTK)
Practical scripts
$_SERVER
is a special PHP reserved variable that contains all the information provided by the web server and is called a superglobal variable. You can use $_SERVER['HTTP_USER_AGENT']
to check what browser the visitors to the page are using.
For IE browser, the value of $_SERVER['HTTP_USER_AGENT']
may be:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0) Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0) Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0) Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
You can determine whether the user agent is IE browser by calling the strpos()
function.
<?php $ua = $_SERVER['HTTP_USER_AGENT']; if(strpos($ua, 'Trident') !== FALSE || strpos($ua, 'MSIE') !== FALSE) { echo 'You are using Internet Explorer.'; } else { echo 'You are not using Internet Explorer.'; }
This code involves the use of strpos()
, !==
and FALSE
.
strpos()
is a built-in function of PHP. Its function is to search for another string (needle) in a string (haystack). If found, the function returns the position of the needle relative to the beginning in the haystack; if not, it returns FALSE.
<?php $haystack = 'hello, world.'; $needle = 'wo'; echo strpos($haystack, $needle);
For the above code, the result returned by strpos()
is 7. For the specific value returned by strpos()
, the calculation method may be different for spaces and Chinese, which will be discussed later.
Processing forms
PHP’s way of processing forms is very convenient. You can use the super global variable $_POST
to obtain data. Use the following method to define a simple HTML form. When the user fills out the form and clicks the submit button, the page action.php
will be called.
Name:Age:
The following code can print data from the form.
Hello, . You are year(s) old.
This code also involves the use of htmlspecialchars()
and (int)
. htmlspecialchars()
enables special characters in HTML to be correctly encoded, so that users will not inject HTML tags or Javascript codes into the page.
Tools
If a worker wants to do his job well, he must first sharpen his tools.
With a good tool, you can get twice the result with half the effort. For efficiency, I like to use VIM and run code from the command line.
As for tools, this post talks about it well. Is there an alternative tool for cmd under window? - windows - SegmentFault.
WampServer and XAMPP are recommended for PHP environment.
(Full text ends)
The above is the content of PHP Getting Started Guide - PHP Manual Notes. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is a server-side scripting language that is used to develop dynamic websites, web applications, and web programs. PHP has a wide range of applications, and both beginners and experienced developers can benefit from it. This article will provide you with an introductory guide to the basic syntax of PHP. If you want to learn PHP programming and build a solid foundation from scratch, you've come to the right place. The basic structure of PHP. A PHP program contains the following three parts: <?php//PHP code?>& on both sides of the code

In web development, file uploading and downloading is a very common requirement. Whether users upload avatars or documents, or administrators ask users to download a file, this function is needed. As a powerful server-side language, PHP naturally provides powerful file operation functions and class libraries, allowing us to easily implement file upload and download functions. This article will introduce the basic process and common functions to implement file upload and download in PHP, and provide sample code. If you are a PHP beginner or are learning file operations

As a popular server-side scripting language, PHP can be used not only for the development of Web applications, but also for TCP/IP programming and network programming. In this article, we will introduce you to the basics of TCP/IP programming and how to use PHP for TCP/IP programming. 1. Basic knowledge of TCP/IP programming TCP/IP protocol is the standard protocol for communication on the Internet. It is composed of two parts: TCP protocol and IP protocol. The TCP protocol is responsible for establishing reliable connections

PHP is a popular front-end programming language. It is powerful, easy to learn and use, and is widely used in website development and maintenance. For beginners, getting started with PHP requires a certain amount of learning and mastering. Here are some guides for beginners in PHP. 1. Learn basic concepts Before learning PHP, you need to understand some basic concepts. PHP is a scripting language that issues instructions to web servers. Simply put, you can use PHP to generate HTML code and send it to the browser to eventually render on the web page

PHP is a widely used programming language, especially in web development, PHP occupies an important position. Among them, JSON is a common data format that can be used to store and transmit data. JSON extensions are provided in PHP to facilitate developers to operate and process JSON data. This article will introduce the basic usage and application scenarios of JSON extension. 1. Basic usage of JSON extension. Convert JSON string into PHP object or array. The json_decode() function in PHP can convert

For PHP beginners, it is very important to understand HTTP status codes. HTTP status code refers to the 3-digit code returned by the web server and is used to indicate the processing result of the client request. This article will introduce some common HTTP status codes and their meanings to help PHP beginners better understand the various HTTP status codes encountered during website development. 200OK200OK is one of the most common HTTP status codes, indicating that the request was successfully processed and a result was returned. When you visit a website, such as

PHP is a very popular programming language that is often used in the field of Internet development. In PHP development, cache settings are a very important part. Caching can improve website performance and user experience, reduce server load, and is one of the common methods for website optimization. This article will introduce you to the introductory guide to setting up PHP cache. 1. What is cache? Caching is to store some frequently accessed data in memory so that it can be quickly obtained the next time it is accessed, avoiding repeated calculations or database queries and improving response speed. PHP, slow

In software development, version management is an extremely important link. Because writing code in a team inevitably requires merging everyone's code. Version management tools can help us track code changes and avoid conflicts when merging. Among them, Git is currently the most popular version management tool, a must-have for both personal development and team collaboration. This article will focus on Git to introduce you to the benefits of using version management tools, the basic concepts and basic operations of Git, and explain how to use Git to collaborate with your team for development. Why do we need versions
