首页  >  文章  >  后端开发  >  PHP中ereg 跟ereg _replace的配合

PHP中ereg 跟ereg _replace的配合

WBOY
WBOY原创
2016-06-13 13:08:50882浏览

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

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn