-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.php
More file actions
96 lines (86 loc) · 2.9 KB
/
Copy pathtools.php
File metadata and controls
96 lines (86 loc) · 2.9 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Created by JetBrains PhpStorm.
* User: savy_m
* Date: 24/05/13
* Time: 15:34
* To change this template use File | Settings | File Templates.
*/
namespace Lib;
class Tools
{
/**
* @param string $name
* @param null $default
* @return mixed
*/
public static function getParam($name, $default = null)
{
return isset($_GET[$name]) ? $_GET[$name] : $default;
}
/**
* @param string $str
* @return string
*/
public static function capitalize($str)
{
$up = $str;
$up[0] = strtoupper($up[0]);
return $up;
}
/**
* @param string $sStr
* @return string
*/
public static function sanitizeForUrl($sStr)
{
$ISOTransChar = array("'" => '-', ' "' => '-',
'áŕĺäâă' => 'a', 'ÁŔĹÄÂĂ' => 'A', 'éčëę' => 'e', 'ÉČËĘ' => 'E',
'íěďîĄ' => 'i', 'ÍĚĎÎ' => 'I', 'óňöôőđ' => 'o', 'ř' => '0', 'ÓŇÖÔŐŘ' => 'O',
'ľúůüű' => 'u', 'ÚŮÜŰ' => 'U', 'ý˙' => 'y', 'Ý' => 'Y',
'ć' => 'ae', 'Ć' => 'AE', '' => 'oe', '' => 'OE',
'ß' => 'B', 'ç' => 'c', 'Ç' => 'C', 'Đ' => 'D', 'ń' => 'n', 'Ń' => 'N',
'Ţ' => 'p', 'ţ' => 'P', '' => 's', '' => 'S');
$tmp = array();
for ($c = 0; $c < strlen($sStr); $c++)
{
$carac = $sStr{$c};
foreach ($ISOTransChar as $chars => $r)
{
if (strpos($chars, $sStr{$c}) > -1 || strpos(utf8_decode($chars), $sStr{$c}) > -1)
{
$carac = $r;
break;
}
}
$tmp[] = $carac;
}
$newStr = implode("", $tmp);
$newStr = preg_replace('/--+/', '-', $newStr);
$newStr = preg_replace('/([^a-z0-9_-])/i', '', $newStr);
$newStr = preg_replace('/([-])$/', '', $newStr);
$newStr = strtolower($newStr);
return $newStr;
}
/**
* @param int $car
* @return string
*/
public static function randomStr($car)
{
$string = "";
$chaine = "abcdefghjklmnpqrstuvwxyABCDEFGHJKLMNPQRSTUVWXYZ123456789";
srand((double)microtime() * 1000000);
for ($i = 0; $i < $car; $i++)
$string .= $chaine[rand() % strlen($chaine)];
return $string;
}
/**
* @param string $stripAccents
* @return string
*/
public static function stripAccents($stripAccents)
{
return strtr($stripAccents, 'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ', 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
}
}