snippet challenge 2 : suggest words starting with TE..


New Member
Wow, snippet challenge 1, saw an array of entries everything from c to php, but a special callout to junkiedogg's entry in hold your breath... assembly :)

Keep them coming in, i'm suprised we hav' nt seen any functional programming language entry. ( will probably post my entry to snippet challenge 2 in erlang!)

With that, let's continue the fun exercise with our next snippet challenge....

Bosky, had a bunch of diwali crackers and too lazy to decide which once to burst first. So, he decided that he would only pick the starting letters of the one he wanted, and his program should take care of the rest.

Your misson:

To take an array [ "technology" , "tandoori", "techeclave", "challenge", "technotrance", "teach","te" ] . (add your own elements into this array if you wish to ) . Take a string in lowe case as input , and if you find that there are other words that begin with this string , then print those .


"c" -> challenge

"t" -> technology, tandoori, techenclave, technotrance, te

"tech" -> technology , techenclave, technotrance

"teche"-> techenclave

hack! 8 )


New Member


function wordStartingWith($str)


    $arr = array("technology" , "tandoori", "techeclave", "challenge", "technotrance", "teach","te");

     $regex = '/^'.$str.'/';

     foreach($arr as $a)


         if(preg_match($regex,$a))echo $a."\n";




This will fail if there are special characters that messes with the regular expressions.

Don't you just LOVE regular expressions??

Assembly? Yea .. maybe tomorrow :) .. now too sleepy.