Introductory Guide-PHP manual notes

Source: Internet
Author: User
Tags html form php and mysql what php

Original: Introductory Guide-PHP manual notes

Once the simple study of PHP, read "PHP and MySQL Web development", as well as the help of a universal search engine. This preparation system to learn a bit, reference is PHP Manual.

What PHP can do

PHP is primarily used for server-side scripting, but PHP's capabilities are far from limited. PHP is mainly used in the following three areas:

    • Server-side scripting
    • Command-line scripting
    • Writing desktop Applications (PHP-GTK)
Useful scripts

$_SERVERis a special PHP reserved variable that contains all the information provided by the Web server, called a Hyper global variable. You can $_SERVER[‘HTTP_USER_AGENT‘] check what browser is being used by the visitor browsing the page.

For IE browsers, $_SERVER[‘HTTP_USER_AGENT‘] the value may be:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like GeckoMozilla/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 strpos() determine whether the user agent is IE browser by calling the 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 strpos() , !== and FALSE uses.

strpos()is a built-in function of PHP that searches for another string (needle) in a string (haystack). If found, the function returns the position of needle in haystack relative to the beginning, or false if not.

<?php $haystack = 'hello, world.';$needle = 'wo';echo strpos($haystack, $needle);

For the above code, strpos() the returned result is 7. For the strpos() specific value returned, the calculation method may be different in space, Chinese, and then discussed later.

Working with Forms

The way PHP handles forms is convenient, and you can use hyper-global variables to $_POST get data. Define a simple HTML form using the following method, when the user fills out the form and clicks the submit button, the page action.php is called.

<form action="action.php" method="post"><p>Name: <input type="text" name="name" /></p><p>Age: <input type="text" name="age" /></p><p><input type="submit" /></p></form>

The following code allows you to print data from a form.

Hello, <?php echo htmlspecialchars($_POST['name']); ?>. You are <?php echo (int)$_POST['age']; ?> year(s) old.

This code also involves the htmlspecialchars() (int) use of and. The htmlspecialchars() special characters in the HTML are correctly encoded so that the user does not inject HTML tags or JavaScript code into the page.

Tools

工欲善其事, its prerequisite.

There is a good tool that can do more with less. To improve efficiency, I prefer to use vim and run the code on the command line.

For the tool, this post is good, the CMD Replacement tool under Window? -Windows-segmentfault.

PHP environments recommend the use of Wampserver and XAMPP.

(End of full text)

Introductory Guide-PHP manual notes

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.