PHP Regex添加span标记

时间:2013-05-25 15:46:00

标签: php regex

我有这些字符串:

$string1 = 'api/1/get/friends/:id/connections';
$string2 = 'api/1/get/search/:name';

如果在斜杠旁边找到字符“”,我需要在斜杠之间添加span标签。

$string1 = 'api/1/get/friends/<span>:id</span>/connections';
$string2 = 'api/1/get/search/<span>:name</span>';

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

这样做:

$result = preg_replace ('~/\K:\w++~', '<span>$0</span>', $string);