<pre>
<?php
$data = <<<DATA
changing
becoming sunny.
dry. becoming sunny.
fine, becoming sunny.
fine. becoming sunny.
fine, cloud clearing.
cloudy early, then fine.
morning cloud. mainly fine.
fine, sunny afternoon.
sunny breaks.
fine. becoming sunny.
fine. morning cloud.
fine. partly cloudy morning.
mainly fine. cloudy morning.
becoming fine. mostly sunny afternoon.
fine and sunny afternoon.
fine. afternoon sunny breaks.
fine. mostly sunny afternoon.
fine. partly sunny afternoon.
fine. sunny afternoon.
fine, becoming sunny.
fine. becoming sunny.
morning cloud then fine.
sunny afternoon.
fine. morning cloud.
dry. becoming mainly sunny.
becoming mostly sunny.
fine. becoming mostly sunny.
mainly sunny.
mostly sunny.
mostly sunny.
mainly sunny.
dry mostly sunny.
dry, mainly sunny.
dry, mostly sunny.
dry. mainly sunny.
dry. mostly sunny.
dry. sunny periods.
dry. mostly sunny.
fine and mainly sunny.
fine, mainly sunny day.
fine, mainly sunny.
fine, mostly sunny day.
fine, mostly sunny.
fine, sunny periods.
fine. lengthy sunny periods .
fine. lengthy sunny periods.
fine. mainly sunny.
fine. mostly sunny.
fine. sunny periods.
fine and mostly sunny.
fine, mostly sunny.
fine. mainly sunny day.
fine. mainly sunny.
fine. mostly sunny day.
fine. mostly sunny.
fine. sunny periods.
fine and mostly sunny.
fine, mainly sunny.
fine, mostly sunny day.
fine. mainly sunny day.
fine. mainly sunny.
fine. mostly sunny.
fine. mostly sunny.
fine. sunny periods.
hot, mostly sunny.
sunny.
sunny.
sunny, less humid.
sunny, but cool.
dry and sunny.
dry, sunny.
dry. sunny.
cool, sunny and dry.
dry and sunny.
dry, sunny.
sunny and dry.
sunny, dry.
fine, dry and sunny.
fine, dry, sunny.
dry and sunny.
dry. sunny day.
dry. sunny.
DATA;
### Split into sections.
$pieces = preg_split('/^\s*$/m', $data);
### Split into lines.
foreach ($pieces as &$piece) {
$piece = preg_split('/\n/', $piece, -1, PREG_SPLIT_NO_EMPTY);
}
### Result.
print_r($pieces);
### Make the replacements.
$conditions = array(
'becoming sunny',
'mostly sunny',
'mostly sunny, dry',
'mostly sunny, fine',
'mostly sunny, hot',
'sunny',
'sunny, dry'
);
$num_pieces = count($pieces);
for ($i = 0; $i < $num_pieces; $i++) {
$num_sub_pieces = count($pieces[$i]);
for ($j = 0; $j < $num_sub_pieces; $j++) {
$pattern = '/^' . preg_quote($pieces[$i][$j]) . '$/m';
$data = preg_replace($pattern, $conditions[$i], $data);
}
}
echo $data;
?>
</pre>