我有一个PHP页面,其中一些从SQL DB提取的字符串列表。文字如下:[用户:6]将他的私家车的颜色[CAR:3]从195到767。
我想要诸如str_replace之类的东西以及函数找到[CAR:CAR_ID]和CAR_ID的位置,将数字替换为[CAR:CAR_ID]
一些想法?我可以使用什么?
要匹配汽车ID,您可以使用此正则: /[car:s*(d+)]/
。
演示:https://regex101.com/r/0zzyiq/4