SearchEngines
in package
Class SearchEngines.
Table of Contents
- $current : string
- Name of currently selected search engine.
- $engines : array<string|int, mixed>
- Associative array with search engine names as key and their base URLs as value.
- __construct() : mixed
- Instantiate the class and allows you to define the current search engine.
- add() : static
- getAll() : array<string, string>
- Returns the array of search engines.
- getCurrent() : string
- Returns the name of the current engine.
- getCurrentUrl() : string
- Returns the base URL of the current engine.
- getUrl() : string
- Returns the base URL of an engine; throws exception if it does not exist.
- makeLink() : string
- Generates a search link with the given query, using the current engine or a specific name.
- set() : static
- Sets a search engine.
- setCurrent() : static
- Sets the current search engine; validates existence.
- setMulti() : static
- Set multiple search engines at once.
Properties
$current
Name of currently selected search engine.
protected
string
$current
= 'google'
$engines
Associative array with search engine names as key and their base URLs as value.
protected
array<string|int, mixed>
$engines
= ['ask' => 'https://www.ask.com/web?q=', 'baidu' => 'https://www.baidu.com/s?wd=', 'bing' => 'https://www.bing.com/search?q=', 'duckduckgo' => 'https://duckduckgo.com/?q=', 'google' => 'https://www.google.com/search?q=', 'yahoo' => 'https://search.yahoo.com/search?p=', 'yandex' => 'https://yandex.com/search/?text=']
Methods
__construct()
Instantiate the class and allows you to define the current search engine.
public
__construct([string|null $current = null ][, array<string, string> $engines = [] ]) : mixed
Parameters
- $current : string|null = null
-
Set the current search engine name or null to use the default
- $engines : array<string, string> = []
-
Custom search engines
Return values
mixed —add()
public
add(string $name, string $url) : static
Parameters
- $name : string
- $url : string
Tags
Return values
static —getAll()
Returns the array of search engines.
public
getAll() : array<string, string>
Return values
array<string, string> —search engine names as keys and URLs as values
getCurrent()
Returns the name of the current engine.
public
getCurrent() : string
Return values
string —getCurrentUrl()
Returns the base URL of the current engine.
public
getCurrentUrl() : string
Return values
string —getUrl()
Returns the base URL of an engine; throws exception if it does not exist.
public
getUrl(string $name) : string
Parameters
- $name : string
-
The search engine name
Return values
string —The search engine base URL
makeLink()
Generates a search link with the given query, using the current engine or a specific name.
public
makeLink(string $query[, string|null $name = null ]) : string
Parameters
- $query : string
-
A string to be URL-encoded
- $name : string|null = null
-
the search engine name or null to use the current
Return values
string —Returns the link to search for the exception
set()
Sets a search engine.
public
set(string $name, string $url) : static
Parameters
- $name : string
-
The search engine name
- $url : string
-
The search engine base URL
Tags
Return values
static —setCurrent()
Sets the current search engine; validates existence.
public
setCurrent(string $name) : static
Parameters
- $name : string
-
The search engine name
Return values
static —setMulti()
Set multiple search engines at once.
public
setMulti(array<string, string> $engines) : static
Parameters
- $engines : array<string, string>