我希望能够用函数的返回替换为我提供函数参数的模式。我调查了preg_replace
但我没有找到一个合适的教程来编写regex
.
例子:
<?php
function generate($content, $type, $id){
$my_onthefly_content = 'Content is '.$content.', type is '.$type.', id is '.$id;
return $my_onthefly_content;
}
$string = '
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.
<p>
{galery:events:30}
</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.
</div>';
?>
我想像这样输出字符串:
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.
<p>
Content is galery, type is events, id is 30
</p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.
</div>