PHP中ereg 跟ereg _replace的配合

WBOY
Release: 2016-06-13 10:54:19
Original
890 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template