hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
hawk enterprises portfolio
 
counter
Select Country/Language FrancaisDeutschEspanolItalianoPortugeseJapaneseKoreanChineseArabicRussianEnglish
Current Projects
portland paranormal.com
xxk search
battlenow
bighawk casino
Hawk Enterprises News

Palindrome PHP test

Tags: , by Hawk on 04.23.08 6:43 pm

I tend to post regularly on some forums around the area and today I saw a fun little question, how to test for palindromes. If you aren’t familiar with Palindromes they come from biology DNA sequences that are complimentary. However most people know them as words that read the same forward and backwords like “straw warts” or “santa at nas”. I took about 5 minutes and wrote this nice little bit of code available below.

Palindrome Test

<center><h2>Palindrome Test</h2>
<span style=”font-size:8pt”>A number or word that reads the same whether written forwards or backwards. Example: 909, 12344321, radar, bob</span>
<br><br>
<form action=”" method=”post”>
Word to Test <input type=”text” name=”testword” value=”straw warts”>
<input type=”submit” name=”submit” value=”Test”>
</form>

<?php
if(isset($_POST['testword'])){
$testword = strtolower( $_POST['testword'] );
$testword = preg_replace( ‘/[^\sa-z0-9]/’, ”, $testword );
if($testword == strrev($testword)){
echo ‘<i>’.$testword. ‘</i> is a <strong>palindrome</strong> that is <strong>’.strlen($testword).’</strong> characters long’;
}
else{
echo ‘Sorry your word ‘.$testword.’ is not a palindrome’;
}
}
?>
<br><br>
Another snippet of fun code from <a href=”http://www.hawkenterprises.org”>Hawk Enterprises</a></center>

If you like it drop me a line.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.