Home  >  Article  >  Backend Development  >  PHP methods for string operations

PHP methods for string operations

墨辰丷
墨辰丷Original
2018-06-08 17:12:341609browse

This article mainly introduces PHP methods for string operations. Interested friends can refer to it. I hope it will be helpful to everyone.

The example in this article describes how PHP simply determines whether two strings are equal. The specific implementation method is as follows:

Definition and usage

strcasecmp() function compares two strings.

Tip: The strcasecmp() function is binary safe and case-insensitive.

Tip: This function is similar to the strncasecmp() function, except that with strncasecmp() you can specify the number of characters for each string to be compared.

The examples are as follows:

<?php 
function strcomp($str1,$str2){ 
  if($str1 == $str2){ 
    return TRUE; 
  }else{ 
    return FALSE; 
  } 
} 
echo strcomp("First string","Second string");
//Returns FALSE 
echo strcomp("A string","A string");
//Returns TRUE 
?>

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implementation of converting images into ASCII codes

switch statement in PHP Usage

Method of counting online people through php

A rating function is implemented based on jQuery through PHP and mysql

How to get the first letter of Chinese pinyin in php program

The above is the detailed content of PHP methods for string operations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn