热搜:NVER 

PHP中ereg 跟ereg _replace的配合

2024-04-25 21:17:02
 PHP中ereg 跟ereg _replace的配合

PHP中ereg 和ereg _replace的配合

<?php
$text = 'This is a {1} day, not {2} and {3}.';
$daytype = array( 1 => 'fine',
????????????????? 2 => 'overcast',
????????????????? 3 => 'rainy' );
while (ereg ('{([0-9]+)}', $text, $regs)) {
? $found = $regs[1];
? $text = ereg_replace("\{".$found."\}", $daytype[$found], $text);
}
echo "$text\n";
// This is a fine day, not overcast and rainy.
?>

结果:This is a fine day, not overcast and rainy