PHP Learning String Courseware _php Tutorial

Source: Internet
Author: User
Tags explode rtrim sprintf alphanumeric characters
Grammar
String strings can be defined in three ways
"(single quote)" "(double quotation mark) <<< (delimiter)

The escape sequence can be interpreted as \ \ \

The biggest feature of double quotes is that variable names are replaced by variable values

Delimiter can be output HTML format as-is


There are two ways of printing a string
echo it belongs to the language structure, not the real function, it differs from print in that it can accept multiple parameters
Print syntax bool (Bourg) print (string AGR) Secondary function output string if a successful return of 1 fails to return a 0 column if the client's browser suddenly hangs up it will cause a failure

String handling functions
LTrim syntax Format: string LTrim (String str); Remove leading spaces from a string
RTrim syntax Format: string RTrim (String str); Remove the suffix space for a string
Trim syntax Format: string Rtim (String str); Remove the two spaces that grandfather wore
Strrev syntax Format: string Strrev (String str); Invert a string to reverse a string
Strtolower syntax Format: string strtolower (String str); Turn the string all lowercase
Strtoupper syntax Format: string strtoupper (String str); Make the string all uppercase
Ucfirst syntax Format: string Ucfirst (String str); Change the first letter of a string to uppercase
Ucworde syntax Format: string Ucworde (String str); Change the first letter of each word of a string to uppercase

Format a string to display
sprintf This function to format a string
sprintf () syntax format string sprintf (String Format,mixed[args] ...)
Example:
$a =sprintf ("% ' *6s", "KKK")
echo $a;
Output Result: ***KKK
b integer turns into binary.
The c integer is converted to the corresponding ASCII character.
D integers are turned into 10.
F single-fold precision numbers are converted to floating-point number.
o integers are turned into octal.
s turns into a string.
The x integer is converted to lowercase 16 rounding.
X integers are converted to uppercase 16 rounding.
printf output formatted string return value integer
Syntax format: int printf (string format, mixed [args] ...);
Example
printf ("%d--%s--%x", 72,72,72);
Output Result: 72--72--48

Splitting and spelling strings
Explode syntax format: array explode (string separator, string string [, int limit])
Implode syntax Format: string implode (shring Glue,array pieces) concatenate array functionality into strings

string comparison
STRCMP syntax format: int strcmp (String 1,string 2) return value is an integer substring
The strcmp string is used to compare the size of a negative number to indicate that 1 is less than 2 positive indicating that 1 is greater than 2 0 equals
strlen syntax format: int strlen (string str); Get string length return value integer
SUBSTR syntax Format: string substr (string string, int start, int [length]);
Gets a partial string that starts the string to stop taking a few words characters omit stop then go to the tail if the start is set to negative to indicate from the back of the image before fetching
Strstr string Strstr (String haystack, string needle); Returns a string from the string to the end of the string that is to say that the following segment string is taken as a boundary point
STRRCHR syntax Format: string STRRCHR (String haystack, string needle); Gets the position of the last occurrence of the string from after the forward intercept string not found returns false
STRPOS syntax format: int strpos (String haystack, string needle, int [offset]); Find the position where the string first appears by default from 0 if the return false is not found
STRRPOS syntax format: int strrpos (String haystack, char needle); The search for the last occurrence of the string does not find the return false return value integer

String fill

Str_pad syntax format can be used for protection of some sensitive information
Str_pad ($input, 10); Produces "Alien"
Str_pad ($input, ten, "-=", str_pad_left); Produces "-=-=-alien"
Str_pad ($input, Ten, "_", Str_pad_both); Produces "__alien___"
Str_pad ($input, 6, "___"); Produces "Alien_"
Str_pad_left String Left Fill
Str_pad_right String Right Fill
Str_pad_both string Ends fill

Substitution of strings
Str_replace () function substitution
There are three ways
Str_replace ("L", "@", "hello"); Replace what replace with what replaces who
$arr 2=array ("%color%", "%title%", "%body%");
$arr 3=array ("Red", "Hello", "World");
Echo Str_replace ($arr 2, $arr 3, "%body%");
How to touch the version

String translation
STRTR () An important substitution function is also called string translation
STRTR also has two ways of calling
STRTR (String $str, String $from, String $to)
$arr 5=array ("Hello" = "hi", "hi" = "Hello");
echo strtr ("Hello is hi", $arr 5);
is to translate what into what
STRTR (string $str, array $replace _pairs)


HTML processing
Processing of HTML entities
Htmlentities (); (Specify conversion mode and character set encoding)
Ent_compat (default): Specify to convert double quotes but keep single quotes
Ent_quotes: To convert double and single quotes at the same time
Ent_noquotes: Indicates that none of the two are converted
Htmlspecialchars (); (Convert <> and other special symbols into entities <>)
Syntax format
$str = "

China

";
echo htmlentities ($STR); Conversion encoding
Echo htmlentities ($str, Ent_quotes, "EUC-JP");//single quote double quotation marks are converted after the encoding of the word
Processing of quotation marks
Stripslashes (); (is Addslashes's inverse function, which shows the transferred character)
Addslashes (); (add ' \ NULL () 4 characters before \ Display)
Cleanup of HTML tags
Strip_tags (); (Cleans HTML hypertext characters in a string)
URL Handling
In addition to the processing of HTML text, the URL address is also processed during web development. Processing URLs mainly include:
Parsing of URL strings
Parse_str (); (Parse request string transform array)
Parse_url (); (resolves the full URL transformation array)
URL encoding Processing
Rawurlencode (); (Replace all non-alphanumeric characters, turn% followed by two-bit 16 binary)
UrlEncode (); (Replace all non-alphanumeric characters, change to% followed by two-bit 16, and the space becomes the + sign)
Rawurldecode (); (resolves a restored URL with a% encoding)
UrlDecode (); (to% # #编码的URL进行解析还原)
Constructs a query string, and so on.
Http_build_query (); (Request string after generating url-encoded)
PHP string. rar

http://www.bkjia.com/PHPjc/319097.html www.bkjia.com true http://www.bkjia.com/PHPjc/319097.html techarticle The syntax string can have three ways of defining the "(single quotation mark)" (double quotation mark) (delimiter) escape sequence that can be interpreted with \\\ as the maximum feature of the double quotation mark is that the variable name is replaced by the variable value ...

  • 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.