| Conditions | 2 |
| Paths | 2 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | function wikiSearch($what) |
||
|
|
|||
| 25 | { |
||
| 26 | // Format: https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&generator=search&utf8=1&exsentences=1&exlimit=max&exintro=1&explaintext=1&gsrnamespace=0&gsrlimit=10&gsrsearch=SEARCH-TEXT |
||
| 27 | $url = 'http://en.wikipedia.org/w/api.php'; |
||
| 28 | $url .= '?action=query&format=json&prop=extracts&generator=search'; |
||
| 29 | $url .= '&utf8=1&exsentences=1&exlimit=max&exintro=1&explaintext=1'; |
||
| 30 | $url .= '&gsrnamespace=0&gsrlimit=10&gsrsearch=' . urlencode($what); |
||
| 31 | |||
| 32 | $options = array( |
||
| 33 | CURLOPT_RETURNTRANSFER => true, // return web page |
||
| 34 | CURLOPT_HEADER => false, // don't return headers |
||
| 35 | CURLOPT_FOLLOWLOCATION => true, // follow redirects |
||
| 36 | CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'], // name of client |
||
| 37 | CURLOPT_SSL_VERIFYPEER => false, |
||
| 38 | ); |
||
| 39 | $ch = curl_init($url); |
||
| 40 | curl_setopt_array($ch, $options); |
||
| 41 | $response = curl_exec($ch); |
||
| 42 | if ($response === false) { |
||
| 43 | throw new Exception('Curl error: ' . curl_error($ch)); |
||
| 44 | } |
||
| 45 | curl_close($ch); |
||
| 46 | return $response; |
||
| 47 | } |
||
| 48 | |||
| 50 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.