function piglatin($text)
{
// These are what we want to find at the start of each word, or failing that we will take the first letter.
$onsets=implode('|', array('th', 'qu', 'br'));
// Move the detected onset to the end and add 'ay'
return preg_replace('~('.$onsets.'|\w)(\w*)~i', '$2$1ay', $text);
}
$text = 'The quick brown fox jumped over the lazy dog';
echo piglatin($text);
|