Home > Backend Development > PHP Tutorial > PHP method to determine whether a string is a palindrome string_PHP tutorial

PHP method to determine whether a string is a palindrome string_PHP tutorial

WBOY
Release: 2016-07-13 10:00:33
Original
1030 people have browsed it

PHP method to determine whether a string is a palindrome string

This article mainly introduces the PHP method to determine whether a string is a palindrome string, example analysis Learned the skills of PHP string manipulation to determine palindrome, which has certain reference value. Friends in need can refer to it

The example in this article describes how PHP determines whether a string is a palindrome string. Share it with everyone for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

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);

?>

1 2

3

4 5

67 8 9 10 11 12
13
14
15 16 17 18 19 20 21 22 23 24
<🎜>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);<🎜> <🎜>?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/973130.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/973130.htmlTechArticleHow PHP determines whether a string is a palindrome string This article mainly introduces PHP to determine whether a string Whether it is a palindrome string method, an example analysis of php operating string judgment...
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