开发者

No ending delimiter '/' found error

I have adjusted a small script to check backlinks. Yet I keep on getting the error

Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in line 17.

<?php
function file_get_contents_curl($url) {开发者_如何学C
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);

return $data;
}

function google_backlink($uri)
{
$url = 'http://www.google.com/search?q=link:facebook.com&hl=en&filter=0';
$v = file_get_contents_curl($url);
preg_match('/<div id="resultStats">About \(.*?)\ ',$v,$s);
$s_number = explode(".", $s[1]);
$i = 0;
if ($s[1]!=0) {
    return $s[1];
} else {
    return ($r[1]) ? $r[1] : '0';
}
}

echo "Google backlink = ".google_backlink($url)."<br />";   
?>

What is wrong with preg_match('/<div id="resultStats">About \(.*?)\ ',$v,$s);


The error is very clear really, you didn't include the trailing /:

preg_match('/<div id="resultStats">About \(.*?)\ /',$v,$s);

I honestly doubt your escape characters are well placed though. Maybe you meant \)?


It does not have a closing /

preg_match('/ pattern /', $subject);

You have a beginning (slash) / but no closing (slash) /

It looks for the pattern you define in between the 2 slashes.


Try changing preg_match('/<div id="resultStats">About \(.*?)\ ',$v,$s);

To preg_match('/<div id="resultStats">About \(.*?)\ /',$v,$s);

/ is a "delimiter" meaning it tells preg_match where the regex pattern ends.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜