使用preg_replace替换动态生成的变量

时间:2014-12-16 15:55:20

标签: regex

$string = "I have the string like "this is the [image1] of the home. this is the [image2] of the home"

我希望[image1]替换为"uploads/1.jpg"[image2]"uploads/2.jpg"

请帮帮我

1 个答案:

答案 0 :(得分:1)

正则表达式:

\[image(\d+)\]

替换字符串:

uploads/\1.jpg