Skip to content

Instantly share code, notes, and snippets.

@Hunter-Dolan
Created February 8, 2011 23:11
Show Gist options
  • Save Hunter-Dolan/817500 to your computer and use it in GitHub Desktop.
Save Hunter-Dolan/817500 to your computer and use it in GitHub Desktop.
Converts DNA to MRNA
<?php
echo "<center><h1>Just so you know... I'm awesome!</h1><br><br><h3>-HD</h3></center>";
echo"<center><form action='?'>Enter DNA Code Here: <input name='dna'><br><input type='submit' value='Convert!'><input type='hidden' name='process' value='true'></form>";
if(isset($_GET['process'])) {
echo "<br><br><br>Your mRNA Code is: <b>";
$dna= str_split($_GET['dna'], 1);
$mrna = array();
foreach ($dna as $l) {
switch($l) {
case 'a' :
case 'A' :
$l = 'U';
break;
case 't' :
case 'T' :
$l = 'A';
break;
case 'g' :
case 'G' :
$l = 'C';
break;
case 'c' :
case 'C' :
$l = 'G';
break;
}
array_push($mrna, $l);
}
$mrna = implode("", $mrna);
$mrna = str_split($mrna, 3);
$last_key = end($mrna);
foreach($mrna as $l) {
echo $l;
if ($last_key == $l) {} else {echo '</b>-<b>';}
}
echo "</b>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment