// 内链处理
if (! ! $tags = $this->model->getTags()) {
// 将A链接保护起来
$rega = "/<a .*?>.*?<\/a>/i";
preg_match_all($rega, $data->content, $matches1);
foreach ($matches1[0] as $key => $value) {
$data->content = str_replace($value, '#rega:' . $key . '#', $data->content);
}
// 执行内链替换
foreach ($tags as $value) {
$data->content = str_replace($value->name, '<a href="' . $value->link . '" target="_blank">' . $value->name . '</a>', $data->content);
}
// 还原A链接
$pattern = '/\#rega:([0-9]+)\#/';
if (preg_match_all($pattern, $data->content, $matches2)) {
$count = count($matches2[0]);
for ($i = 0; $i < $count; $i ++) {
$data->content = str_replace($matches2[0][$i], $matches1[0][$matches2[1][$i]], $data->content);
}
}
}
你需要程序员的拥抱
###如果是执行很多个操作,一般是for循环,执行到1 return跳出就好了
看不懂
###看晕了
###去牛客,CSDN问问
###去淘宝
###找技术
###还是找技术解决吧,如果公司没有就去淘宝找
本文来自投稿,不代表微盟圈立场,如若转载,请注明出处:https://www.vm7.com/a/ask/80269.html