回文:正序和倒序完全相同
<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>$string);<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>$stra);<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>; }</count></strlen></code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介绍了 PHP之判断输入的字符串是不是回文,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。