则正替换文章里面的关键字

 '我28岁', 'url' => 'http://www.wo28sui.com', 'num' => 3),
array('title' => '有没有爱情', 'url' => 'http://www.aiqing.com', 'num' => 3),
array('title' => '毕竟越长', 'url' => 'http://www.bjyd.com', 'num' => 2),
array('title' => '测试信息', 'url' => 'http://www.ceshi.com', 'num' => 2),
array('title' => 'test', 'url' => 'http://www.test.com', 'num' => 1),
);

foreach($find as $k => $v)
{
if(strpos($str, $v['title']))
{
$pattern = '/'.$v['title'].'/';
$replace = "{$v['title']}";
$str = preg_replace($pattern, $replace, $str, $v['num']);
}
}

echo $str;

  

转载于:https://www.cnblogs.com/Abner3721/p/5466422.html

你可能感兴趣的:(则正替换文章里面的关键字)