Important functions of PHP are much less Accumulated-author: zccst8, stringbase64_encode (stringdata); this function encodes strings with MIMEBASE64. This encoding method enables smooth transmission of Chinese text or images over the network. The BASE64 encoded string contains only English letters (uppercase and lowercase), Arabic numerals, plus signs, and backslash (backslash). It contains 64 basic characters and does not contain other special characters. it is an important function of PHP.
Accumulated more-author: zccst
8, string base64_encode (string data );
This function encodes the string with MIME BASE64. This encoding method enables smooth transmission of Chinese text or images over the network. The BASE64 encoded string contains only English letters (uppercase and lowercase), Arabic numerals, plus signs, and backslash (backslash). It contains 64 basic characters and does not contain other special characters. Therefore, it is named BASE64. The encoded string is about 1/3 longer than the original string. For more BASE64 encoding information, see section 6.8 of RFC2045.
7, similar_text
The similar_text () function is used to calculate the number of matching characters of two strings. It can also calculate the similarity between the two strings (expressed in percentages ).
Parameter description
String1 is required. Specifies the first string to be compared.
String2 is required. Specifies the second string to be compared.
Percent is optional. Specifies the name of the variable that stores the percentage similarity.
similar_text("Hello World","Hello Peter",$percent);echo $percent;
Output: 63.6363636364
6, spl_autoload_register ('autoloader ');
function autoloader($className){ if(file_exists(dirname(__FILE__)."/$className.php")){ include dirname(__FILE__)."/$className.php"; if(class_exists($className,false)){ return true; } } return false;}
Annotation:
Bool class_exists (string $ class_name [, bool $ autoload = true])
The second parameter: Whether or not to call _ autoload by default.
Autoload can be disabled only when the second parameter is false to save costs.
_ Autoload mechanism:
See another article: php autoload mechanism.
5, addslashes () and stripslashes ()
The addslashes () function adds a backslash before the specified predefined character. The predefined characters are: single quotes (') double quotation marks (") backslash (\) NULL
$str = "Is your name O'reilly?";// Outputs: Is your name O\'reilly?echo addslashes($str);
The stripslashes () function deletes the backslash added by the addslashes () function.
4, get_magic_quotes_gpc ()
Int get_magic_quotes_gpc (void)
Returns the current configuration setting of magic_quotes_gpc
Keep in mind that attempting to set magic_quotes_gpc at runtime will not work.
For more information about magic_quotes, see this security section.
Annotation: obtain the value of the PHP environment variable magic_quotes_gpc (GPC, Get/Post/Cookie. If 0 is returned, this function is disabled. if 1 is returned, this function is enabled.
When magic_quotes_gpc is enabled, all '(single quotation marks),' (double quotation marks), \ (backslash) and null characters are automatically converted to escape characters containing the backslash.
When magic_quotes_gpc = On, the system automatically handles single quotes and other issues. it does not need to use addslashes () or stripslashes (), but if addslashes () is used to add data (), stripslashes () is required for data display ()
When magic_quotes_gpc = Off, the system will not handle single quotation marks and other issues. Therefore, addslashes () must be used when inserting data, and stripslashes () is not required when displaying data ().
What should I do when I make a program? Based on the above two situations, you can:
Whether magic_quotes_gpc is On or Off, we use addslashes () when adding data. when On, we must use stripslashes (), and when Off, we cannot use stripslashes ().
How can we determine whether to be On or Off? Use get_magic_quotes_gpc ().
Example:
// 1. store the data in the database $ Content = addslashes ("This is data, no matter whether there are single quotes or variables"); // Insert data to the database, the code is omitted // 2, get $ Content = "data read from the database" from the database; if (get_magic_quotes_gpc () {$ Content = stripslashes ($ Content);} echo $ Content; /************ example 2 ****************/echo get_magic_quotes_gpc (); // 1 echo $ _ POST ['lastname']; // O \ 'reillyecho addslashes ($ _ POST ['lastname']); // O \\\ 'reillyif (get_magic_quotes_gpc () {$ lastname = stripslashes ($ _ POST ['lastname']);} else {$ lastname = $ _ POST ['lastname'];} // If using MySQL $ lastname = mysql_real_escape_string ($ lastname); echo $ lastname; // O \ 'Reilly $ SQL = "INSERT INTO lastnames (lastname) VALUES ('$ Lastname ')";
3, get_file_contents ($ fileName)
Reads a file into a string.
The file_get_contents () function is used to read the file content into a string.
File_put_contents (string $ filename, string $ data [, int $ flags [, resource $ context])
Write a string to a file
2, str_replace (array ('\ r \ n'), array ("\ n"), $ str)
1, strip_tags ($ v)
Prototype: string strip_tags (string $ str [, string $ allowable_tags])
Explanation: This function tries to return a string with all NUL bytes, HTML and PHP tags stripped from a given str. It uses the same tag stripping state machine as the fgetss () function.
Example:
$text = 'Test paragraph.
Other text';echo strip_tags($text);echo "\n";// Allow and echo strip_tags($text, '
');
Output:
Test paragraph. Other text
Test paragraph.
Other text