当前位置: 代码迷 >> PHP >> PHP中ereg 跟ereg _replace的配合
  详细解决方案

PHP中ereg 跟ereg _replace的配合

热度:262   发布时间:2012-10-26 10:30:59.0
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

  相关解决方案