In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "introduction of PHP common functions and common troubleshooting questions", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "PHP common function introduction and common troubleshooting questions" bar!
Introduction to common library functions of PHP
1. Common functions for PHP string manipulation
1. Determine the length of the string
Int strlen (string str)
two。 Compare two strings
A. the strcmp function makes a binary-safe comparison of two strings and is case-sensitive
Int strcmp (string str1,string str2)
b. Compare two strings in a case-insensitive manner
Int strcasecmp (string str1,string str2)
3. Find the same part of two strings
Int strspn (string str1,string str2)
4. Find the different parts of two strings
5.int strcspn (string str1,string str2)
6. Handle string case
a. Convert all strings to lowercase
String strtolower (string str)
b. Convert all strings to uppercase
String strtoupper (string str)
c. Capitalize the first character of a string
String ucfirst (string str)
d. Convert the first character of each word in a string to uppercase
String ucwords (string str)
7. Conversion between string and HTML
a. Convert newline characters to HTML termination tags
String bl2br (string str)
b. Convert special characters to wieldHTML equivalent form (unparsed format)
String htmlentities (string str [, int quote_style [, int charset]])
String htmlspecialchars (string str [, int quote_style [, string charset]])
c. Convert HTML to plain text and remove all php and html tags
String strip_tags (string str [, string allowable_tags])
d. Convert text to HTML equivalent
Array get_html_translaction_table (int table [, int quote_style])
e. Create a custom conversion list
String strtr (string str,array replacements)
8. Substitution function of regular expression function
A. the strtok function parses strings based on a predefined list of strings
String strtok (string str,string tokens): returns everything that was before tokens was encountered
b. Parse strings based on predefined delimiters
Array explode (string separator,string str [, int limit]): split strings
c. Convert an array to a string
String implode (string delimiter, array array)
d. Find the first occurrence of a string
Int strpos (string str,string substr [, int offset])
e. Find the last occurrence of the string
Int strrpos (string str,char substr [, offset])
f. Replace all instances of a string with another string
Mixed str_replace (string occurrence,mixed replacement,mixed str [, int count])
g. Get part of a string strstr returns the rest of the string at the beginning of the first occurrence of a predefined string
String strstr (string str,string occurrence)
h. Returns a portion of the string based on a predefined offset
String substr (string str,int start [, ing length]): start can be negative, indicating the beginning of the penultimate.
i. Determine the frequency of occurrence of strings
Int substr_count (string str,string substring)
j. Replace part of a string with another string
String substr_replace (string str,string replacement,int start [, int length])
9. Populate and weed out strings
a. Crop characters starting from a string
String ltrim (string str [, string charliset])
b. Trim characters from the end of a string
String rtrim (string str [, string charliset])
c. Trim characters from both ends of a string
String trim (string str [, string charliset])
d. Fill string
String str_pad (string str,int length [, string pad_string [, int pad_type]])
10. Character and word count
a. Character count in string
Mixed count_chars (string str [, mode])
b. Total number of words in string count
Mixed str_word_count (string str [, int format])
2. Three form validation functions commonly used in PHP Web development
(1) isset ();-- suitable for detecting the existence of this parameter. Used to avoid referencing variables that do not exist
Definition and scope: used to test whether a variable has a value (including zero false, or an empty string returns true, but not NULL), that is, "http://localhost/?fo=" can also pass the test, so it is not applicable." But if it is "http://localhost/" parameter does not contain fo parameter, it can be detected with isset, and isset ($_ GET ['fo']) returns false.
Not applicable: this function is not suitable for an effective way to validate text in an html form. To check whether the user input text is valid, you can use empty ()
(2) empty ();-- A function that is best used to check whether a variable has a null value.
Definition and scope: used to check whether variables have null values, including: empty string, 0 false null or false, which all return false, that is, when "http://localhost/?fo="" or "http://localhost/?fo=0"", the result detected by empty is ture
Not applicable: not suitable for detecting parameters that can be 0
(3) is_numeric ();-- check whether the variable is a number
Definition and scope: check whether the variable is a number, only applicable to check the number
Not applicable: but if the parameter name does not exist, there will be an error, so it is not suitable for first-layer detection
Another useful validation function is checkdate (month,day,$year), which is used to confirm whether a date exists or has existed in the past
Comprehensive example:
This is the form:
The copy code is as follows:
Form validation example
Pass effective value, pass null value, pass 0 value.
Gender: male: female
Empty
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.