一个正则加法和减法的运算,解决方法

WBOY
Release: 2016-06-13 13:52:18
Original
1380 people have browsed it

一个正则加法和减法的运算,
$result= "中华民国96年 ";
$result   =   preg_replace( '/中华民国([0-9]+)年/s ', '公元1912+\\1-1年 ',$result);

行运结果是:公元1912+96-1年


我要的结果是:公元2007年  

怎么才能让 "1912+96-1 "运算结果出来??

------解决方案--------------------
$result= "中华民国96年 ";
echo $result = preg_replace( '/中华民国([0-9]+)年/es ', 'ch(\\1) ',$result);

function ch($s)
{
$y = 1912 + $s - 1;
return '公元 '. $y . '年 ';
}
?>

output:

公元2007年

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