升木 发表于 2017-4-7 06:13:21

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 ('{(+)}', $text, $regs)) {
  $found = $regs;
  $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
页: [1]
查看完整版本: PHP中ereg 和ereg _replace的配合