<?php
$className = "flag brasileña";
$alt = explode(" ", $className);
?>
<div class='<?php echo $className ?>' title='<?php echo $alt[1] ?>'></div>
Assuming class name always has two words and alt always take the second word and since you mentioned you want to do it by php the class name is generated dynamically.
This is how you can do it but this wont serve any purpose. Whats that you want to do with adding second word to "alt".