php.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /* ------------------------------------------------------------------------------------
  3. * Goosle - A meta search engine for private and fast internet fun.
  4. *
  5. * COPYRIGHT NOTICE
  6. * Copyright 2023-2024 Arnan de Gans. All Rights Reserved.
  7. *
  8. * COPYRIGHT NOTICES AND ALL THE COMMENTS SHOULD REMAIN INTACT.
  9. * By using this code you agree to indemnify Arnan de Gans from any
  10. * liability that might arise from its use.
  11. ------------------------------------------------------------------------------------ */
  12. class PHPnetRequest extends EngineRequest {
  13. public function get_request_url() {
  14. $this->query = str_replace("_", "-", str_replace("php ", "", $this->query));
  15. return "https://www.php.net/manual/function.".urlencode($this->query);
  16. }
  17. public function parse_results($response) {
  18. $results = array();
  19. $xpath = get_xpath($response);
  20. if($xpath) {
  21. // Scrape the page
  22. $title = $xpath->query("//div/section/div[@class='refentry']/div/h1[@class='refname']")[0]->textContent;
  23. if(is_null($title)) return array();
  24. $php_versions = $xpath->query("//div/section/div[@class='refentry']/div/p[@class='verinfo']")[0]->textContent;
  25. $purpose = $xpath->query("//div/section/div[@class='refentry']/div/p[@class='refpurpose']")[0]->textContent;
  26. $usage = $xpath->query("//div/section/div[@class='refentry']/div[@class='refsect1 description']/div[@class='methodsynopsis dc-description']")[0]->textContent;
  27. $response = array (
  28. // Required
  29. "title" => sanitize($title),
  30. "text" => "<p><em><small>".$php_versions."</small></em></p><p>".$purpose."</p><p>".highlight_string("<?php ".trim($usage)." ?>", 1)."</p>",
  31. "source" => "https://www.php.net/manual/function.".urlencode($this->query)
  32. );
  33. return $response;
  34. } else {
  35. return array(
  36. "title" => "Oof...",
  37. "text" => "PHP.net didn't provide any answers. Try again later."
  38. );
  39. }
  40. }
  41. }
  42. ?>