<?php

function x($s){$r='preg_replace';$s=$r('/ +/',' ',$s);$s=$r(array('/ \^COMMA/','/ \^COLON/','/ \^SEMICOLON/','/ \^PERIOD/','/ \^BANG/','/\^DASH/','/ \^HYPHEN /','/ \^EMDASH /','/\^OPENQUOTE /','/ \^CLOSEQUOTE/'),array(',',':',';','.','!','-','-','--','"',',"'),$s);$s=$r('/(^\W*\w|([\.!]| ")\W+\w)/e','strtoupper("$0")',$s);$s=$r('/([,\.!]),/','\1',$s);$s=$r('/(\w)( "\w)/e','"$1,".strtoupper("$2")',$s);echo$s;}

echo x("once upon a time ^COMMA there was a horse ^PERIOD that horse cost me $50 ^PERIOD ^OPENQUOTE eat your stupid oats ^COMMA already ^BANG ^CLOSEQUOTE I told the horse ^PERIOD the horse neighed back ^OPENQUOTE no ^CLOSEQUOTE and died ^PERIOD I always hated that stupid horse ^DASH his name was Franklin ^HYPHEN James the III ^PERIOD I decided to go and buy a new animal ^EMDASH a cow ^EMDASH named Franklin ^HYPHEN James ^SEMICOLON however ^COMMA this time he was the first in his line, so his full name was simply Franklin ^HYPHEN James ^PERIOD That cow sucked ^PERIOD I wish I could have the talking horse named Ed ^PERIOD One time, I went to a circus and they had a banner that said ^COMMA ^OPENQUOTE COME SEE ED ^COLON THE TALKING HORSE ^BANG ^CLOSEQUOTE but I had no money so I did not get to see him ^PERIOD THE END ^PERIOD");

