-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib_utility.php
62 lines (56 loc) · 1.61 KB
/
lib_utility.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Telegram Bot Sample
* ===================
* UWiClab, University of Urbino
* ===================
* Support library. Don't change a thing here.
*/
/**
* Gets whether the script is running from the Command Line Interface.
*
* @return bool True if running from the CLI.
*/
function is_cli() {
return (php_sapi_name() === 'cli');
}
/**
* Mixes together parameters for an HTTP request.
*
* @param array $orig_params Original parameters or null.
* @param array $add_params Additional parameters or null.
* @return array Final mixed parameters.
*/
function prepare_parameters($orig_params, $add_params) {
if(!$orig_params || !is_array($orig_params)) {
$orig_params = array();
}
if($add_params && is_array($add_params)) {
foreach ($add_params as $key => &$val) {
$orig_params[$key] = $val;
}
}
return $orig_params;
}
/**
* Checks whether a text string starts with another.
* Performs a case-insensitive check.
*
* @param $text String to search in.
* @param $substring String to search for.
* @return bool True if $text starts with $substring.
*/
function starts_with($text = '', $substring = '') {
return (strpos(mb_strtolower($text), mb_strtolower($substring)) === 0);
}
/**
* Extracts the command payload from a string.
* Returns the string following the first command in a string (i.e., given
* input "/start 123", returns "123").
*
* @param $text String to search in.
* @return string Command payload, if any, or empty string.
*/
function extract_command_payload($text = '') {
return mb_ereg_replace("^\/[a-zA-Z0-9_]*( |$)", '', $text);
}