PHP Starter Guide-PHP Manual notes

Source: Internet
Author: User
Tags php and mysql what php
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 ' Yo U is using Internet Explorer. ';} else {echo ' is 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.

Name:age:

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

Hello,. You is 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)

The above is the PHP Primer-PHP Manual note content, more relevant content please follow topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.