Usage of strncasecmp string comparison functions in php

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff to enter the strncasecmp string comparison function in php. usage instructions: we usually use strtolower or strtoupper to convert the string to lower-case or upper-case before determining whether the string is equal. But this requires two conversions. Mostly

Welcome to the Linux community forum and interact with 2 million technical staff> Go To The strncasecmp string comparison function in php. usage instructions: we usually use strtolower or strtoupper to convert the string to lower-case or upper-case before determining whether the string is equal. But this requires two conversions. Mostly

Welcome to the Linux community forum and interact with 2 million technicians>

Usage of strncasecmp string comparison functions in php:

We usually use strtolower or strtoupper to convert the string to lower-case or upper-case before determining whether the string is equal.

But this requires two conversions. Most of the time, we are for character set conversion will be like this, such as determining whether the parameter passed in UTF-8, the five character writing, but more, such as UTF-8, Utf-8, what should we do with UTF-8? Strtolower? Strupper? No ......

Strncasecmp ($ a, $ B, $ length ......

If the return value is 0, it is equal. How can we determine?

Strncasecmp ($ str, 'utf-8', 5) = 0. Then, the input parameter is utf8. Is it convenient?

These functions are not commonly used. I can see that the function is used in yii framework. When processing events and determining whether the first two characters are on, this is the case. I also learned a trick.

Definition and usage

The strncasecmp () function compares the first n characters of a string (Case Insensitive ).

This function returns the following values:

0? If the string is equal

<0? If string1 is smaller than string2

> 0? If string1 is greater than string2

Syntax

Syntax

Strncasecmp (string1, string2, length)

Parameter Description

Required parameter of string1. Specifies the first string object involved in the comparison

Required parameter of string2. Specify the second string object involved in the comparison

Length required parameter. Specify the number of characters for Parameter comparison in each string

Note: The strncasecmp () function is binary accurate and case-insensitive.

Instance

Echo strncasecmp ("Hello world! "," Hello phpzixue.cn! ", 6 );

?>

The result is as follows:

0

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.