Php string filter function

Source: Internet
Author: User
Tags character set html tags mysql tutorial

<? Nl2br (); // to <br/>

Addslashes (); strips tutorial lashes (); // Escape Special characters when operating on the database tutorial
Definition: The addslashes () function adds a backslash before a specified predefined character.
Syntax: addslashes (string)
Note: By default, the magic_quotes_gpc command of php is on, and addslashes () is automatically run for all get, post, and cookie data (). Do not use addslashes () for strings that have been escaped by magic_quotes_gpc, because this causes double-layer escape. In this case, you can use the get_magic_quotes_gpc () function for detection.
<? Php
Function addslashes_str ($ str ){
$ Str = addslashes ($ str );
$ Str = str_replace ($ str ,";",';');
Return $ str;
}
Function stripslashes_str ($ str ){
$ Str = stripslashes ($ str );
$ Str = str_replace ($ str ,';',";");
Return $ str;
}
?>

 
Chop (); // remove the right space of the string
Trim (); // remove all spaces in the string
Ltrim (); // remove the left space of the string
Htmlspecialchars (); // converts '$', '"', '<', '>' to the corresponding html entity
Htmlentities (); // Convert all html tags to corresponding html entities
Array explode (string separator, string str); // splits the string
String implode (string separator, array arr); // connection string
Strtoupper (); strtolower (); // converts the case sensitivity
Ucfirst (); // only converts the first character to uppercase.
Ucwords (); // converts the first letter of each word to uppercase.
Iconv ()
Php internal code conversion function, same as above
Because iconv () is a bug in gb2312 conversion, it should be handled like this
Iconv ("UTF-8", "gb2312 // ignore", $ str)

Mb_convert_encoding ()
Php internal code conversion function
Version (php 4> = 4.0.6, php 5)
This function can convert various encodings to each other.
Mb_convert_encoding ($ str, "gb2312", "UTF-8 ");


Mysql tutorial _ real_escape_string ()
Definition: Special characters in strings used in function escape SQL statements.
Syntax: mysql_real_escape_string (string, connection)
Note: This function escapes special characters in string and considers the current character set to be connected. Therefore, it can be safely used for mysql_query ().
?>

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.