-
Notifications
You must be signed in to change notification settings - Fork 3
/
extract.php
34 lines (34 loc) · 1.08 KB
/
extract.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$str = $_POST["text"];
$url = 'http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction';
$appid = 'pSQDjJHV34FkRSTyZoZrdF0oVAumFMwp5WsFWNa4zE7CcgWIS9CS_kQIZjvCB9DSieJysDDS6z6uv5ZfKi3I';
$output = 'php';
$context = urlencode($str);
$context = substr($context, 0, 7000);
$url = $url . '?appid=' . $appid . '&output=' . $output . '&context=' . $context;
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$response = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
$total = count($response['ResultSet']['Result']) - 1;
echo $total;
$i=0;
foreach ($response['ResultSet']['Result'] as $key => $term)
{
if ($i < $total)
{
print $term . ", \n";
}
elseif ($i == $total)
{
print $term;
}
$i++;
}
?>