我d可能会检查你是否通过它们循环,并删除双http的,例如:
$request_url ='YOUR URL';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($result); // loads your html
$xpath = new DOMXPath($doc);
$needle = 'blog';
$nodelist = $xpath->query("//a[contains(@href, '" . $needle . "')]");
$validUrls = array();
for($i=0; $i < $nodelist->length; $i++) {
$node = $nodelist->item($i);
$curUrl = $node->getAttribute('href');
if (substr_count($curUrl,'http')===1) {
$validUrls[] = $curUrl;
}
}
var_dump($validUrls); // all urls with only one "http"
http://stackoverflow.com/questions/1188129/replace-urls-in-text-with-html-links/16509122#16509122 –
'preg_match('/(http。*?)http /',' https://foo.bar.baz/q=http://blah.com',$ matches);' - 任何两个'http'之间的任何匹配。 – Damon