PHP method to determine whether it is a palindrome string

墨辰丷
Release: 2023-03-31 17:52:01
Original
3257 people have browsed it

This article mainly introduces the method of PHP to determine whether a string is a palindrome string. The example analyzes the techniques of PHP operating strings to determine palindrome. It has certain reference value. Friends who need it can refer to it

The example in this article describes how PHP determines whether a string is a palindrome string. The specific implementation method is as follows:

<?php
 function ishuiwen($str){
  $len=strlen($str);
  $l=1;
  $k=intval($len/2)+1;
   for($j=0;$j<$k;$j++){
    if (substr($str,$j,1)!=substr($str,$len-$j-1,1))
     {
  $l=0;
  break;
   }
 }
 if ($l==1)
 {
 return 1;
 }
 else
 {
 return -1;
  }
 }
 $str=12321;
 echo ishuiwen($str);
?>
Copy after login

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

Related recommendations:

php analysis and manipulation of strings and generation of tag clouds

php converts arbitrary base numbers into 10 The hexadecimal method

php implements generating a tree list from the results of the database query

The above is the detailed content of PHP method to determine whether it is a palindrome string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template