Php basic tutorial php built-in function example tutorial _ PHP Tutorial

Source: Internet
Author: User
Php basic tutorial php built-in function instance tutorial. So love micro-network now explains first php built-in functions case-sensitive conversion functions text html tags processing functions case-sensitive function copy code: strtolower () strtoupper () so love micro-network now explains php built-in functions
Case-sensitive conversion functions
Text html tag processing function

Case-sensitive functions

The code is as follows:


Strtolower ()
Strtoupper ()
Ucfirst ()
Ucword ()



String formatting functions related to HTML tags

The code is as follows:


Nl2br ()
Htmllentities ()
Htmlspecialchars ()
Stripslashes ()
Strip_tags ()
Number_format ()
Strrev ()
Md5 ()



In php, all string processing functions are not modified on the original string, but return a newly formatted string.

The code is as follows:


// Convert to lowercase
$ A = 'www .jb51.net ';
Echo strtolower ($ );
// Result: www.jb51.net

// Convert to uppercase
$ A = 'www .jb51.net ';
Echo strtoupper ($ );
// Result: WWW.jb51.net

// Uppercase letters
$ A = 'www .jb51.net ';
Echo ucfirst ($ );
// Result: Www.jb51.net

// Uppercase letters of each word
$ A = 'I love you ';
Echo ucword ($ );
// Result: I Love You

/*
Tip: We all know the case sensitivity. do you think the case sensitivity is different from the case sensitivity and the case sensitivity?
In Windows, php is not case sensitive, but cannot be case insensitive in linux.
For example
When the class is automatically loaded
Function _ autoload ($ className ){
Include strtolower ($ className). '. class. php ';
}
$ Obj = new MyClass;
In this way, myclass. class. php will be loaded.
Because the file name is often lowercase, it must be converted to lowercase.
?>
*/

// Nl2br converts spaces into entities
Because the line feed shown in the browser is usually
For example, in the form message book, it must be converted. Otherwise, if the line cannot be broken, more spaces will be processed as a space.
$ A ='
I
Love
You
';
Echo $;
Echo nl2br ($ );
Result 1: I love you.
Result 2:
I
Love
You

// If you do not perform html tag processing for form submission, the style or js code will be displayed and run directly.
/*


When you enter
Www.jb51.net
A large font is displayed upon submission.
But you wanted
Result of www.jb51.net
So proceed
When you enter script alert ('www .jb51.net') script
Javascript will be run once submitted
If this is not the case, you have to deal with it to prevent hackers from finding the entrance to your attack.
The default form submission method is get.
*/
// When you enter

Www.jb51.net


Echo htmlspecialchars ($ _ GET ['title']); // filtered
Result:

Www.jb51.net


When you view the source code, you will know that <and> have been replaced with <& gt, and the page prototype is displayed.
If you do not want to handle this

Some copied articles have their own tag styles, which will disrupt your page layout. css conflicts may occur.
Htmllentities () function user and htmlspecialchars () are not used in the opposite way.

The strip_tags () function can be used when you need to keep the tag.
Echo strip_tags ($ _ GET ['title'],'

');
The submitted result is displayed when you view the source code.

No

/*
Add the input I love 'jb51 ';
The submission result is I love \ 'jb51 \ '. the backslash is escaped.
What should I do if I want to output the original text?
You can use this php function stripslashes ()
Cancel escape
Echo stripslashes ($ _ GET ['title']);
The result is I love 'jb51 ';
What if html tags are contained?
I love 'jb51'
What should I do with prototype output? I can combine two functions to use what I have already said.
Echo htmlspecialchars (stripslashes ($ _ GET ['title']);
Result: I love 'jb51'
*/

// Number_format () this function is used to format the currency function. different countries have different habits, so the display of the required currency is different. for example, the Chinese money in the mall is usually in this format.
Use commas (,) to retain the number of decimal places'
This function is easy to use.
Number_format ($ money, which indicates the number of decimal points reserved. 'What are the decimal points separated 'and 'What are the decimal points separated ')
$ Price = '1970. 100 ';
Echo number_format ($ money, 2 ,',','.');
Result: 123.465.789, 23
Echo number_format ($ money, 2, '.', ','); // Chinese
Result: 123,465,789.23

// Strrev () returns the string
$ Str = 'http: // www.jb51.net ';
Echo strrev ($ str );
Result: moc. tenwii. www //: ptth

// Md5 indicates that the user name and password must be encrypted to prevent hackers.
$ A = 'admin ';
Echo $ B = md5 ($ );

Handler case-sensitive conversion function text html tag processing function case-sensitive function code: strtolower () strtoupper ()...

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.