Ajax and PHP Based Insult Auto-Completer
This is kind of a novelty web page. It gives you lots of cool TV-14-rated insults in case you're having trouble thinking of them. But it also uses Ajax and PHP to prompt you once you start typing. You type "a" and the script gives you a nice set of insults, such as "ass clown."
The reason we created this is to show the code involved. When you type, the onKeyUp() event runs the Ajax prompt() script which takes the input box's current value and uses xmlhtml to send it as a query string from your browser to the prompt.php script on the server where it gets compared to hundreds of other insults in a PHP array. The code for the comparing is at the bottom of this page. The PHP function count() counts the number of elements in the array for the FOR loop. For comparing, input and array are both converted to lower case with strtolower(). The number of characters typed so far is the number of characters in each array elements that get compared to the input string. If the input matches part or all of an array element, that element if put into the $prompt string and the script keeps looping until all relevant elements have been added to the $prompt string. If no match is made, then the prompt "no prompt" is stuck in the respose string to send back to the browser. If there are matches, all of these are stuck in the respose string to send back to the browser.
Type an insult:
Prompt:
The relevant code on this page:
<P><B>
<script type="text/javascript">
function prompt(str){
if (str.length==0){document.getElementById("prompt").innerHTML="";return;}
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("prompt").innerHTML=xmlhttp.responseText;}}
xmlhttp.open("GET","prompt.php?q="+str,true);xmlhttp.send();}
</script>
</B></P>
<P><B>
<div class='k'><p><b>Type an insult:</b></p>
<form>
Insult: <input type="text" onkeyup="prompt(this.value)" size="20" />
</form>
<p>Prompt: <span id="prompt"></span></p></div>
<p>The prompt.php file:</p>
<?php
$i[]="ass wipe";
$i[]="ass clown";
$i[]="ass face";
$i[]="ass monkey";
$i[]="assface";
$i[]="assmonkey";
$i[]="a-hole";
$i[]="ass muncher";
$i[]="ass kisser";
$i[]="ass licker";
$i[]="ass bandit";
$i[]="ass breath";
$i[]="asswipe";
$i[]="assmuncher";
$i[]="asskisser";
$i[]="asslicker";
$i[]="assbandit";
$i[]="assbreath";
$i[]="assclown";
$i[]="arse";
$i[]="arsehole";
$i[]="arse hole";
$i[]="air head";
$i[]="airhead";
$i[]="bugger";
$i[]="bug";
$i[]="brownnoser";
$i[]="baby";
$i[]="badass";
$i[]="baldy";
$i[]="baldie";
$i[]="brownnose";
$i[]="bubble head";
$i[]="bubblehead";
$i[]="brown nose";
$i[]="brown noser";
$i[]="butt wipe";
$i[]="butt hole";
$i[]="butt muncher";
$i[]="butt kisser";
$i[]="butt licker";
$i[]="butt bandit";
$i[]="butt breath";
$i[]="butt pirate";
$i[]="buttwipe";
$i[]="butthole";
$i[]="buttmuncher";
$i[]="buttkisser";
$i[]="buttlicker";
$i[]="buttbandit";
$i[]="buttbreath";
$i[]="buttpirate";
$i[]="butthead";
$i[]="butt head";
$i[]="bitch";
$i[]="biatch";
$i[]="biotch";
$i[]="bastard";
$i[]="buffoon";
$i[]="brat";
$i[]="bunghole";
$i[]="bung hole";
$i[]="bung wad";
$i[]="bungwad";
$i[]="bungbreath";
$i[]="bung breath";
$i[]="bum";
$i[]="beast";
$i[]="boob";
$i[]="booger";
$i[]="buttnugget";
$i[]="buttmonkey";
$i[]="butt nugget";
$i[]="butt monkey";
$i[]="bimbo";
$i[]="crap for brains";
$i[]="crapforbrains";
$i[]="crackpot";
$i[]="crackwhore";
$i[]="crack whore";
$i[]="coke whore";
$i[]="cokewhore";
$i[]="crack ho";
$i[]="coot";
$i[]="crud";
$i[]="cowpie";
$i[]="cow pie";
$i[]="cracker";
$i[]="chicken";
$i[]="crybaby";
$i[]="cry baby";
$i[]="crapface";
$i[]="crap face";
$i[]="crapbreath";
$i[]="crap breath";
$i[]="corn ball";
$i[]="choad";
$i[]="cornball";
$i[]="chump";
$i[]="creep";
$i[]="cow";
$i[]="crook";
$i[]="dirtbag";
$i[]="dodo";
$i[]="dick head";
$i[]="dummy";
$i[]="dickhead";
$i[]="dog";
$i[]="dog breath";
$i[]="dogbreath";
$i[]="dogface";
$i[]="dog face";
$i[]="dingus";
$i[]="dick lick";
$i[]="dicklick";
$i[]="dick licker";
$i[]="dicklicker";
$i[]="douchebag";
$i[]="douche bag";
$i[]="dumbass";
$i[]="dumb ass";
$i[]="dumbhead";
$i[]="dumb head";
$i[]="damn fool";
$i[]="dick";
$i[]="dickwad";
$i[]="dick wad";
$i[]="dillweed";
$i[]="dill weed";
$i[]="dillhole";
$i[]="dill hole";
$i[]="dope";
$i[]="dingus";
$i[]="dingis";
$i[]="dirt bag";
$i[]="dimwad";
$i[]="dim wad";
$i[]="dimbulb";
$i[]="dim bulb";
$i[]="dork";
$i[]="dorkface";
$i[]="dork face";
$i[]="dolt";
$i[]="donkeydick";
$i[]="donkey dick";
$i[]="dork";
$i[]="dweeb";
$i[]="dink";
$i[]="fartknocker";
$i[]="fart knocker";
$i[]="fartlicker";
$i[]="fart licker";
$i[]="fart sniffer";
$i[]="fathead";
$i[]="fat head";
$i[]="farthead";
$i[]="fart head";
$i[]="fartsniffer";
$i[]="fool";
$i[]="fartbag";
$i[]="fart bag";
$i[]="fartface";
$i[]="fart face";
$i[]="fartbreath";
$i[]="fart breath";
$i[]="fart";
$i[]="fatty";
$i[]="fart nugget";
$i[]="fartnugget";
$i[]="fat ass";
$i[]="fatass";
$i[]="freak";
$i[]="fake";
$i[]="flake";
$i[]="faker";
$i[]="floozie";
$i[]="fogy";
$i[]="foul";
$i[]="gangster";
$i[]="geezer";
$i[]="gomer";
$i[]="goofball";
$i[]="gook";
$i[]="geek";
$i[]="goon";
$i[]="halfass";
$i[]="half ass";
$i[]="halfwit";
$i[]="half wit";
$i[]="hammerhead";
$i[]="hairbag";
$i[]="hair bag";
$i[]="ho";
$i[]="hoe";
$i[]="hag";
$i[]="ho bag";
$i[]="hobag";
$i[]="hooker";
$i[]="hick";
$i[]="idiot";
$i[]="imbecile";
$i[]="jerk";
$i[]="jerkoff";
$i[]="jerk off";
$i[]="jerk ass";
$i[]="jerk face";
$i[]="jerkass";
$i[]="jerkface";
$i[]="junkie";
$i[]="knobhead";
$i[]="knob head";
$i[]="knothead";
$i[]="knot head";
$i[]="kiss ass";
$i[]="knucklenuts";
$i[]="kissass";
$i[]="knuckle nuts";
$i[]="knucklehead";
$i[]="knuckle head";
$i[]="lame";
$i[]="lameass";
$i[]="lamebrain";
$i[]="lame brain";
$i[]="lame ass";
$i[]="looney";
$i[]="limp dick";
$i[]="limpdick";
$i[]="lowbrow";
$i[]="louse";
$i[]="low brow";
$i[]="lecher";
$i[]="lardo";
$i[]="lard butt";
$i[]="lardbutt";
$i[]="lard ass";
$i[]="lardass";
$i[]="lunkhead";
$i[]="lunk head";
$i[]="leebo";
$i[]="lame-o";
$i[]="lech";
$i[]="lowlife";
$i[]="lunk";
$i[]="lunkhead";
$i[]="lunk head";
$i[]="lush";
$i[]="loser";
$i[]="meathead";
$i[]="mimbo";
$i[]="meat head";
$i[]="melvin";
$i[]="mofo";
$i[]="mo fo";
$i[]="moron";
$i[]="motherbeater";
$i[]="mouth breather";
$i[]="mouthbreather";
$i[]="nincompoop";
$i[]="nerd";
$i[]="numbnuts";
$i[]="numb nuts";
$i[]="numb skull";
$i[]="numbskull";
$i[]="nummy";
$i[]="oof";
$i[]="old bag";
$i[]="old fart";
$i[]="parrot breath";
$i[]="parrotbreath";
$i[]="pussy";
$i[]="pig";
$i[]="peckerhead";
$i[]="poophead";
$i[]="pecker head";
$i[]="poop head";
$i[]="poopbreath";
$i[]="poop breath";
$i[]="peckerbreath";
$i[]="pecker breath";
$i[]="penisbreath";
$i[]="penis breath";
$i[]="penisface";
$i[]="penis face";
$i[]="peckerhead";
$i[]="pecker head";
$i[]="pecker";
$i[]="poop";
$i[]="prick";
$i[]="pisshead";
$i[]="piss head";
$i[]="piss ant";
$i[]="pissant";
$i[]="puke";
$i[]="pud";
$i[]="putz";
$i[]="queef";
$i[]="raunch";
$i[]="rectum breath";
$i[]="rectumbreath";
$i[]="redneck";
$i[]="roadhog";
$i[]="schmuck";
$i[]="scrotumbreath";
$i[]="scrotum breath";
$i[]="scrotum";
$i[]="scrotum licker";
$i[]="scrotumlicker";
$i[]="skag";
$i[]="slacker";
$i[]="slub";
$i[]="stool";
$i[]="schlong";
$i[]="scag";
$i[]="slut";
$i[]="skank";
$i[]="skunk";
$i[]="simpleton";
$i[]="simple tool";
$i[]="sow";
$i[]="sissy";
$i[]="terd";
$i[]="terdbreath";
$i[]="terd breath";
$i[]="tool";
$i[]="tub";
$i[]="tubby";
$i[]="twit";
$i[]="twinkie";
$i[]="twink";
$i[]="ugly";
$i[]="uncool";
$i[]="wuss";
$i[]="wimp";
$i[]="weakling";
$i[]="wang";
$i[]="whore";
$i[]="whoremonger";
$i[]="wacko";
$i[]="wank";
$i[]="wanker";
$i[]="whiner";
$i[]="whine baby";
$i[]="whinebaby";
$z=$_GET["q"];
if (strlen($z) > 0){
$prompt="";
for($n=0; $n<count($i); $n++){
if (strtolower($z)==strtolower(substr($i[$n],0,strlen($z)))){
if ($prompt==""){$prompt=$i[$n];}
else{$prompt=$prompt." , ".$i[$n];}}}}
if ($prompt == ""){$r="no prompt";}else{$r=$prompt;}
echo $r;
?>