21,880
社区成员
发帖
与我相关
我的任务
分享
$str = '{xx}您好,请您于{xx}到{xx}开会。';
$info = '小明,今天下午4点,一楼会议室
小张,明天上午10点,二楼会议室
小李,明天下午14点,三楼会议室';
$infos = explode(PHP_EOL, $info);
preg_match_all('/{.*?}/', $str, $matches);
$pattern = array_map(function ($val){
return '/'.preg_quote($val, '/').'/';
}, $matches[0]);
$infos = array_map(function ($item) use ($pattern, $str){
return preg_replace ($pattern, explode(',', $item), $str, 1);
}, $infos);
print_r(implode(PHP_EOL, $infos));
$str = '{姓名}您好,请您于{日期}到{地点}开会。';
$info = '小明,今天下午4点,一楼会议室
小张,明天上午10点,二楼会议室
小李,明天下午14点,三楼会议室';
$infos = explode(PHP_EOL, $info);
preg_match_all('/{.*?}/', $str, $matches);
$infos = array_map(function ($item) use ($matches, $str){
return str_replace ($matches[0], explode(',', $item), $str);
}, $infos);
print_r(implode(PHP_EOL, $infos));
那就这样?
$str = '{姓名}您好,请您于{日期}到{地点}开会。';
$info = '小明,今天下午4点,一楼会议室
小张,明天上午10点,二楼会议室
小李,明天下午14点,三楼会议室';
$infos = explode(PHP_EOL, $info);
$infos = array_map(function ($item) use ($str){
return str_replace(['{姓名}', '{日期}', '{地点}'], explode(',', $item), $str);
}, $infos);
print_r(implode(PHP_EOL, $infos));
这样行吗?