Home  >  Article  >  Backend Development  >  How to compare the length of two strings in php, length of two strings in php_PHP tutorial

How to compare the length of two strings in php, length of two strings in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:46:34908browse

How to compare the length of two strings in php, the length of two strings in php

The example in this article describes the method of comparing the length of two strings in php. Share it with everyone for your reference. The specific implementation method is as follows:

This code calculates the length of two strings and then calculates their difference

<&#63;php 
// This will return a number of how many more characters the longest string has 
function str_compare_length($str1, $str2){ 
  $len1 = strlen($str1); 
  $len2 = strlen($str2); 
  return abs($len1 - $len2); 
} 
echo str_compare_length("This is the first string", "This is the second string"); 
&#63;>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1031483.htmlTechArticleHow to compare the length of two strings in php, the length of two strings in php. This example describes how to compare two strings in php String length method. Share it with everyone for your reference. The specific implementation methods are as follows...
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