首頁  >  文章  >  後端開發  >  PHP中ereg 跟ereg _replace的配合

PHP中ereg 跟ereg _replace的配合

WBOY
WBOY原創
2016-06-13 10:54:19890瀏覽

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