PHP determines whether the input string is a palindrome

WBOY
Release: 2016-07-28 08:26:10
Original
1292 people have browsed it

Palindrome: forward and reverse order are exactly the same

<code><span>$string</span>=<span>"abc126321cba"</span>;
  <span>$stra</span>=<span>array</span>();
  <span>$strb</span>=<span>array</span>();
  <span>$res</span>=checkhuiwen(<span>$string</span>);
  <span><span>function</span><span>checkhuiwen</span><span>(<span>$string</span>)</span>{</span><span>//输入字符串转换为数组</span><span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span><strlen(<span>$string</span>);<span>$i</span>++){
        <span>$stra</span>[<span>$i</span>]=<span>$string</span>[<span>$i</span>];
      }
       <span>//逆序输出数组array_reverse</span><span>$strb</span>=array_reverse(<span>$stra</span>);
       <span>//判断两数组是否相等,相等为回文</span><span>for</span>(<span>$i</span>=<span>0</span>;<span>$i</span><count(<span>$stra</span>);<span>$i</span>++){
       <span>if</span>(<span>$stra</span>[<span>$i</span>]!=<span>$strb</span>[<span>$i</span>]){
          <span>return</span><span>1</span>;
          <span>break</span>;
       }     
  }
  <span>return</span><span>2</span>;
  }
  <span>if</span>(<span>$res</span>==<span>2</span>){
    <span>echo</span><span>"YES"</span>;
  }<span>else</span>{
    <span>echo</span><span>"NO!"</span>;
  }</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced how PHP determines whether the input string is a palindrome, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

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