你能告诉如何用正则表达式替换吗 [英] Could you tell how to replace by regular expression

查看:20
本文介绍了你能告诉如何用正则表达式替换吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我如何用 preg-replace 替换字符串吗(需要正则表达式):

Could you tell how to replace string by preg-replace (need regular expression):

/user/{parent_id}/{action}/step/1

在数组的等效值处:

array('parent_id'=>32, 'action'=>'some');

制作:

/user/32/some/step/1

<小时>

补充

这是一个典型的问题,所以我可能不知道变量的名称是什么


Addition

This is a typical problem, so I probably will not know what the names of variables come

推荐答案

$arr = array('parent_id'=>32, 'action'=>'some');

$out = str_replace(array_keys($arr),array_values($arr),$in);

不需要正则表达式!

这篇关于你能告诉如何用正则表达式替换吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆