-
Notifications
You must be signed in to change notification settings - Fork 0
/
basics.php
52 lines (40 loc) · 1.66 KB
/
basics.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
<?php
function get_current_url($clean_get_requests = false){
$request_uri = $_SERVER['REQUEST_URI'];
if($clean_get_requests && strpos($request_uri, '?') !== false){
$request_uri = explode('?', $request_uri);
$request_uri = $request_uri[0];
}
return trim((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http') . '://'. $_SERVER['HTTP_HOST'] . $request_uri, '/');
}
function convert_non_english($str){
return iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
}
function get_summary($content, $length = 30){
$content = trim(str_replace("\n", ' ', strip_tags(htmlspecialchars_decode($content))));
return (strlen($content) > $length ? trim(trim(mb_substr($content, 0, $length), '.')).'...' : $content);
}
function format_date($date, $db_format = false){
$format = ($db_format ? 'Y-m-d H:i:s' : 'd F Y');
return date($format, strtotime($date));
}
function check_html_validity($html){
$html = str_replace('//>', '/>', preg_replace('#<(img|br|input)(.*?)>#si', '<$1$2/>', $html));
preg_match_all('#<([a-zA-Z0-9]+)(.*?)!/>#si', $html, $start_tags);
foreach($start_tags[1] as $start_tag){
preg_match_all('#<'.preg_quote($start_tag).'#si', $html, $start_tag_occurences);
preg_match_all('#</'.preg_quote($start_tag).'>#si', $html, $end_tag_occurences);
if(count($start_tag_occurences[0]) != count($end_tag_occurences[0])){
return false;
}
}
return true;
}
function get_ip(){
foreach(['HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'] as $key){
if(isset($_SERVER[$key])){
return $_SERVER[$key];
}
}
}
// to be continued...