此代码基于变量中的所有链接的快捷方式$datatext
我想从快捷方式中排除特定域,例如google.com|msn.com
代码 :
<?php
$datatext = "bla bla bla bla <br /><a href=\"http://www.google.com\" target=\"_blank\">http://www.google.com</a><br /><br /><a href=\"http://www.msn.com\" target=\"_blank\">http://www.msn.com</a><br /><br /><a href=\"http://www.edaf.at\" target=\"_blank\">http://www.edaf.at</a> bla bla bla bla bla bla bla bla";
$wreplacer_first = 'target="_blank">www.';
$wreplacer_second = 'target="_blank">http://www.';
$data = str_replace("$wreplacer_first","$wreplacer_second",$datatext);
$reg_exUrl = "#\<a href=\"(.*)\" target=\"(.*)\"\>(.*)<\/a\>#Ui";
preg_match_all($reg_exUrl, $data, $matches);
$links = $matches[1];
foreach ($links as $val)
{
$turl=$val;
$link="http://v.gd/create.php?format=simple&url=".$turl."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_URL, $link);
$content = curl_exec($ch);
curl_close($ch);
$datatext = str_replace($turl,"$content", $datatext);
}
echo $datatext;
?>