我很难找到解决问题的方法。
我在变量中有一个像这样的数组:
$myarray = Array (
[0] => Orange
[1] => Black
[2] => White
[3] => Yellow
[4] => Red
);
[基本上,我需要在字符串中搜索数组的单词,并用相同的单词替换它们,但是使用链接。
例如,来自:
$string = "My content contains orange and also black";
收件人:
$string = "My content contains <a href="www.domain.com/orange">orange</a> and also blue";
您可以使用str_replace,检查link
$string = "My content contains orange and also black";
$string = str_replace("orange","<a href='http://www.example.com/orange'>orange</a>",$string);