Google has its own api. You can read the documentation here.
An example with the deprecated api:
$search = "some unique contents";
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Referer: http://your_site.com\r\n" // see the terms of service
)
);
$context = stream_context_create($opts);
if (false !== $data = file_get_contents('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="'.urlencode($search).'"', false, $context)) {
$json = json_decode($data, true);
if (!empty($json['responseData']['results'])) {
echo "This is plagiarized!";
}
}
Note that the query its wrappet between "
. That's tell google to find the exact phrase.