【发布时间】:2011-03-06 12:51:46
【问题描述】:
我想用指向该个人资料的链接替换文本中的姓名。
$text = "text with names in it (John) and Jacob.";
$namesArray("John", "John Plummer", "Jacob", etc...);
$LinksArray("<a href='/john_plom'>%s</a>", "<a href='/john_plom'>%s</a>", "<a href='/jacob_d'>%s</a>", etc..);
//%s shout stay the the same as the input of the $text.
但是如果需要的话可以改变de数组。
我现在使用 2 个数组在使用 str_replace。像这样$text = str_replace($namesArray, $linksArray, $text);
但是用“点”或“)”或任何类似的东西在结尾或开头替换名称。我怎样才能让替换来处理这样的文本。
输出喊叫是"text with names in it (<a.....>John</a>) and <a ....>Jacob</a>."
【问题讨论】:
-
那么你想删除
Jacob.中的一个点吗? -
你的
$namesArray是什么样的?
标签: php arrays replace preg-replace