<?php
$weather="天气预报 今天:{1} 天气:<font color=red>{2}</font> 风向:{3} 气温:{4}";
$daytype=array(
1=>"3月31日",
2=>"多云转晴",
3=>"偏北风四级",
4=>"8-15度"
);
while(ereg("{([0-9])}",$weather,$regs)){
$found=$regs[1];
$weather=ereg_replace("\{".$found."\}",$daytype[$found],$weather);
}
echo $weather;
?>
这段代码中的while(ereg("{([0-9])}",$weather,$regs)){
$found=$regs[1];是什么意思,是循环输出$reg数组到$found嘛,$found=$regs[1]为什么键值为一?正则正则表达式
$weather="天气预报 今天:{1} 天气:<font color=red>{2}</font> 风向:{3} 气温:{4}";
$daytype=array(
1=>"3月31日",
2=>"多云转晴",
3=>"偏北风四级",
4=>"8-15度"
);
while(ereg("{([0-9])}",$weather,$regs)){
$found=$regs[1];
$weather=ereg_replace("\{".$found."\}",$daytype[$found],$weather);
}
echo $weather;
?>
这段代码中的while(ereg("{([0-9])}",$weather,$regs)){
$found=$regs[1];是什么意思,是循环输出$reg数组到$found嘛,$found=$regs[1]为什么键值为一?正则正则表达式
整个代码就是将$weather中的 {1},{2},{3},{4} 替换为相应的值