PHP String Function Learning Strstr () _php Tutorial

Source: Internet
Author: User

PHP String Function Learning Strstr ()


This article mainly introduces the PHP string function Learning Strstr (), this article explains its definition and usage, parameter description, hints and comments, as well as a number of use examples, the need for friends can refer to the following

The code is as follows:


/*
Definition and usage
The Strstr () function searches for the first occurrence of a string in another string.
The function returns the remainder of the string (from the matching point). returns false if the searched string is not found.
Grammar
String Strstr (string, search)

Parameter description
string is required. Specifies the string to be searched.
Search required. Specifies the string to search for. If the argument is a number, search for characters that match the ASCII value of the number

Hints and Notes
Note: This function is binary safe.
Note: The function is case-sensitive. For a case-insensitive search, use STRISTR ().
If you only want to determine if needle exists in haystack, use the Strpos () function, which is faster and consumes less memory.
*/
$str = ". The specified string to be searched ";
$s = "of";
Echo strstr ($str, $s). "
";
Echo Mb_strstr ($str, $s, ' utf-8 '). "
";
Echo Mb_strstr ($str, $s, true, ' utf-8 '). "
";
Echo Mb_strstr ($str, $s, false, ' utf-8 '). "

";

/*
Definition and usage
The STRRCHR () function finds the last occurrence of a string in another string and returns all characters from that position to the end of the string.
If it fails, it returns false.
Grammar
STRRCHR (String,char)
Parameter description
string is required. Specifies the string to be searched.
Char required. Specifies the character to find. If the parameter is a number, the character that matches the ASCII value of the number is searched.
*/
Echo STRRCHR ($str, $s). "
";
Echo MB_STRRCHR ($str, $s, ' utf-8 '). "
";
Echo MB_STRRCHR ($str, $s, true, ' utf-8 '). "
";
Echo MB_STRRCHR ($str, $s, false, ' utf-8 '). "

";

$str = "Hello world! Hello world! ";
$s = "world";
Echo STRRCHR ($str, $s). "
";
Echo MB_STRRCHR ($str, $s, ' utf-8 '). "
";
Echo MB_STRRCHR ($str, $s, true, ' utf-8 '). "
";
Echo MB_STRRCHR ($str, $s, false, ' utf-8 '). "

";

/*
Definition and usage
The STRTR () function converts a specific character in a string.
Grammar
STRTR (String,from,to)
Or
STRTR (String,array)
Parameter description
String1 required. Specifies the string to convert.
From required (unless an array is used). Specifies the character to be changed.
To required (unless an array is used). Specifies the character to change to.
Array is required (unless you use from and to). An array in which the key is the original character and the value is the target character.
Description
If the from and to lengths are different, the format is the shortest length.
*/
Echo strtr ("Hilla Warld", "ia", "EO"). "
";
$arr = Array ("Hello" = "Hi", "World" = "Earth");
Echo strtr ("Hello World", $arr). "

";

Echo STRTR ("If omitted, use internal character encoding", "internal", "external"). "
";
$arr = Array ("If" and "if", "then" = "then");
Echo STRTR ("If omitted, use internal character encoding", $arr). "

";
?>

http://www.bkjia.com/PHPjc/975117.html www.bkjia.com true http://www.bkjia.com/PHPjc/975117.html techarticle PHP String Function Learning Strstr () This article mainly introduces the PHP string function Learning Strstr (), this article explains its definition and usage, parameter description, hints and comments, as well as several make ...

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