Skip to content

Instantly share code, notes, and snippets.

@hectorip
Created February 12, 2013 20:51
Show Gist options
  • Save hectorip/4773260 to your computer and use it in GitHub Desktop.
Save hectorip/4773260 to your computer and use it in GitHub Desktop.
<?php
$datos=<<<EOT
4
Estimado presidente
Debemos platicar sobre esta situacion su pueblo esta muy hinchado
y no pensamos plantar mas bombas
queremos paz DE UNA VEZ LE DIGO Que haga lo que haga no seremos sus esclavoz
EOT;
$lineas=preg_split("/((\r?\n)|(\r\n?))/", $datos);
$n_lineas=$lineas[0];
for($i=1; $i<=$n_lineas;$i++){
$nueva_linea="";
foreach(preg_split("/ +/", $lineas[$i]) as $palabra){
if(preg_match('/[pP].*[rR]$/',$palabra)){
$n_letras=strlen($palabra);
$nueva_linea.=str_pad("", $n_letras,"#")." ";
}
else if(preg_match('/^[hH].*(?=([oO]))/',$palabra)){
$n_letras=strlen($palabra);
$nueva_linea.=str_pad("", $n_letras,"#")." ";
}
else {
$nueva_linea.=strtoupper($palabra)." ";
}
}
echo $nueva_linea."<br/>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment