【发布时间】:2012-03-14 01:01:40
【问题描述】:
$string = ":abc and :def have apples.";
$replacements = array('Mary', 'Jane');
应该变成:
Mary and Jane have apples.
现在我正在这样做:
preg_match_all('/:(\w+)/', $string, $matches);
foreach($matches[0] as $index => $match)
$string = str_replace($match, $replacements[$index], $string);
我可以使用 preg_replace 之类的东西一次运行吗?
【问题讨论】:
-
This 是使用关联数组的方法。