No ending delimiter '/' found error

 ̄綄美尐妖づ 提交于 2019-12-01 18:49:58

问题


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) {
$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);


回答1:


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 \)?




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6445133/no-ending-delimiter-found-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!