PHP中ereg跟ereg_replace的配合
时间:2021-07-01 10:21:17
帮助过:5人阅读
PHP中ereg 和ereg _replace的配合
$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