Completed
Push — master ( 56221e...3c95ac )
by Yannick
07:57
created

Common::str2int()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 8
nc 4
nop 2
dl 0
loc 11
rs 8.2222
c 0
b 0
f 0
1
<?php
2
require_once(dirname(__FILE__).'/libs/simple_html_dom.php');
3
require_once(dirname(__FILE__).'/libs/uagent/uagent.php');
4
require_once(dirname(__FILE__).'/settings.php');
5
6
class Common {
7
	//protected $cookies = array();
8
	
9
	/**
10
	* Get data from form result
11
	* @param String $url form URL
12
	* @param String $type type of submit form method (get or post)
13
	* @param String|Array $data values form post method
14
	* @param Array $headers header to submit with the form
15
	* @return String the result
16
	*/
17
	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
18
		global $globalProxy, $globalForceIPv4;
19
		$ch = curl_init();
20
		curl_setopt($ch, CURLOPT_URL, $url);
21
		if (isset($globalForceIPv4) && $globalForceIPv4) {
22
			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
23
				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24
			}
25
		}
26
		if (isset($globalProxy) && $globalProxy != '') {
27
			curl_setopt($ch, CURLOPT_PROXY, $globalProxy);
28
		}
29
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31
		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
32
		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
33
		//curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
34
//		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
35
		if ($useragent == '') {
36
			curl_setopt($ch, CURLOPT_USERAGENT, UAgent::random());
37
		} else {
38
			curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
39
		}
40
		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41
		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
42
		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
43
		if ($type == 'post') {
44
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
45
			if (is_array($data)) {
46
				curl_setopt($ch, CURLOPT_POST, count($data));
47
				$data_string = '';
48
				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
49
				rtrim($data_string, '&');
50
				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
51
			} else {
52
				curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
53
			}
54
		}
55
		if ($headers != '') {
56
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
57
		}
58
		if ($cookie != '') {
59
			if (is_array($cookie)) {
60
				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
61
			} else {
62
				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
63
			}
64
		}
65
		if ($referer != '') {
66
			curl_setopt($ch, CURLOPT_REFERER, $referer);
67
		}
68
		$result = curl_exec($ch);
69
		$info = curl_getinfo($ch);
70
		//var_dump($info);
71
		curl_close($ch);
72
		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
73
			echo "Cloudflare Detected\n";
74
			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
75
			$useragent = UAgent::random();
76
			cloudflare::useUserAgent($useragent);
77
			if ($clearanceCookie = cloudflare::bypass($url)) {
78
				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
79
			}
80
		} else {
81
			return $result;
82
		}
83
	}
84
	
85
	private function curlResponseHeaderCallback($ch, $headerLine) {
86
		//global $cookies;
87
		$cookies = array();
88
		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
89
			$cookies[] = $cookie;
90
		return strlen($headerLine); // Needed by curl
91
	}
92
93
	public static function download($url, $file, $referer = '') {
94
		global $globalDebug;
95
		$fp = fopen($file, 'w');
96
		$ch = curl_init();
97
		curl_setopt($ch, CURLOPT_URL, $url);
98
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
99
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
100
		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
101
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
102
		curl_setopt($ch, CURLOPT_FILE, $fp);
103
		curl_exec($ch);
104
		if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch);
105
		curl_close($ch);
106
		fclose($fp);
107
	}
108
	
109
	/**
110
	* Convert a HTML table to an array
111
	* @param String $data HTML page
112
	* @return Array array of the tables in HTML page
113
	*/
114
	public function table2array($data) {
115
		if (!is_string($data)) return array();
116
		if ($data == '') return array();
117
		$html = str_get_html($data);
118
		if ($html === false) return array();
119
		$tabledata=array();
120
		foreach($html->find('tr') as $element)
121
		{
122
			$td = array();
123
			foreach( $element->find('th') as $row)
124
			{
125
				$td [] = trim($row->plaintext);
126
			}
127
			$td=array_filter($td);
128
			$tabledata[] = $td;
129
130
			$td = array();
131
			$tdi = array();
132
			foreach( $element->find('td') as $row)
133
			{
134
				$td [] = trim($row->plaintext);
135
				$tdi [] = trim($row->innertext);
136
			}
137
			$td=array_filter($td);
138
			$tdi=array_filter($tdi);
139
			$tabledata[]=array_merge($td,$tdi);
140
		}
141
		$html->clear();
142
		unset($html);
143
		return(array_filter($tabledata));
144
	}
145
	
146
	/**
147
	* Convert <p> part of a HTML page to an array
148
	* @param String $data HTML page
149
	* @return Array array of the <p> in HTML page
150
	*/
151
	public function text2array($data) {
152
		$html = str_get_html($data);
153
		if ($html === false) return array();
154
		$tabledata=array();
155
		foreach($html->find('p') as $element)
156
		{
157
			$tabledata [] = trim($element->plaintext);
158
		}
159
		$html->clear();
160
		unset($html);
161
		return(array_filter($tabledata));
162
	}
163
164
	/**
165
	* Give distance between 2 coordonnates
166
	* @param Float $lat latitude of first point
167
	* @param Float $lon longitude of first point
168
	* @param Float $latc latitude of second point
169
	* @param Float $lonc longitude of second point
170
	* @param String $unit km else no unit used
171
	* @return Float Distance in $unit
172
	*/
173
	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174
		if ($lat == $latc && $lon == $lonc) return 0;
175
		$dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515;
176
		if ($unit == "km") {
177
			return round($dist * 1.609344);
178
		} elseif ($unit == "m") {
179
			return round($dist * 1.609344 * 1000);
180
		} elseif ($unit == "mile" || $unit == "mi") {
181
			return round($dist);
182
		} elseif ($unit == "nm") {
183
			return round($dist*0.868976);
184
		} else {
185
			return round($dist);
186
		}
187
	}
188
189
	/**
190
	* Check is distance realistic
191
	* @param int $timeDifference the time between the reception of both messages
192
	* @param float $distance distance covered
193
	* @return whether distance is realistic
194
	*/
195
	public function withinThreshold ($timeDifference, $distance) {
196
		$x = abs($timeDifference);
197
		$d = abs($distance);
198
		if ($x == 0 || $d == 0) return true;
199
		// may be due to Internet jitter; distance is realistic
200
		if ($x < 0.7 && $d < 2000) return true;
201
		else return $d/$x < 1500*0.27778; // 1500 km/h max
202
	}
203
204
205
	// Check if an array is assoc
206
	public function isAssoc($array)
207
	{
208
		return ($array !== array_values($array));
209
	}
210
211
	public function isInteger($input){
212
	    return(ctype_digit(strval($input)));
213
	}
214
215
216
	public function convertDec($dms,$latlong) {
217
		if ($latlong == 'latitude') {
218
			$deg = substr($dms, 0, 2);
219
			$min = substr($dms, 2, 4);
220
		} else {
221
			$deg = substr($dms, 0, 3);
222
			$min = substr($dms, 3, 5);
223
		}
224
		return $deg+(($min*60)/3600);
225
	}
226
	
227
	public function convertDM($coord,$latlong) {
228
		if ($latlong == 'latitude') {
229
			if ($coord < 0) $NSEW = 'S';
230
			else $NSEW = 'N';
231
		} elseif ($latlong == 'longitude') {
232
			if ($coord < 0) $NSEW = 'W';
233
			else $NSEW = 'E';
234
		}
235
		$coord = abs($coord);
236
		$deg = floor($coord);
237
		$coord = ($coord-$deg)*60;
238
		$min = $coord;
239
		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
0 ignored issues
show
Bug introduced by
The variable $NSEW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
240
	}
241
	
242
	/**
243
	* Copy folder contents
244
	* @param       string   $source    Source path
245
	* @param       string   $dest      Destination path
246
	* @return      bool     Returns true on success, false on failure
247
	*/
248
	public function xcopy($source, $dest)
249
	{
250
		$files = glob($source.'*.*');
251
		foreach($files as $file){
252
			$file_to_go = str_replace($source,$dest,$file);
253
			copy($file, $file_to_go);
254
		}
255
		return true;
256
	}
257
	
258
	/**
259
	* Check if an url exist
260
	* @param	String $url url to check
261
	* @return	bool Return true on succes false on failure
262
	*/
263
	public function urlexist($url){
264
		$headers=get_headers($url);
265
		return stripos($headers[0],"200 OK")?true:false;
266
	}
267
	
268
	/**
269
	* Convert hexa to string
270
	* @param	String $hex data in hexa
271
	* @return	String Return result
272
	*/
273
	public function hex2str($hex) {
274
		$str = '';
275
		$hexln = strlen($hex);
276
		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
277
		return $str;
278
	}
279
	
280
	
281
	public function getHeading($lat1, $lon1, $lat2, $lon2) {
282
		//difference in longitudinal coordinates
283
		$dLon = deg2rad($lon2) - deg2rad($lon1);
284
		//difference in the phi of latitudinal coordinates
285
		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
286
		//we need to recalculate $dLon if it is greater than pi
287
		if(abs($dLon) > pi()) {
288
			if($dLon > 0) {
289
				$dLon = (2 * pi() - $dLon) * -1;
290
			} else {
291
				$dLon = 2 * pi() + $dLon;
292
			}
293
		}
294
		//return the angle, normalized
295
		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
296
	}
297
	
298
	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) {
299
		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
300
		$a = -($lon2-$lon1);
301
		$b = $lat2 - $lat1;
302
		$c = -($a*$lat1+$b*$lon1);
303
		$d = $a*$lat3+$b*$lon3+$c;
304
		if ($d > -$approx && $d < $approx) return true;
305
		else return false;
306
	}
307
	
308
	public function array_merge_noappend() {
309
		$output = array();
310
		foreach(func_get_args() as $array) {
311
			foreach($array as $key => $value) {
312
				$output[$key] = isset($output[$key]) ?
313
				array_merge($output[$key], $value) : $value;
314
			}
315
		}
316
		return $output;
317
	}
318
	
319
320
	public function arr_diff($arraya, $arrayb) {
321
		foreach ($arraya as $keya => $valuea) {
322
			if (in_array($valuea, $arrayb)) {
323
				unset($arraya[$keya]);
324
			}
325
		}
326
		return $arraya;
327
	}
328
329
	/*
330
	* Check if a key exist in an array
331
	* Come from http://stackoverflow.com/a/19420866
332
	* @param Array array to check
333
	* @param String key to check
334
	* @return Bool true if exist, else false
335
	*/
336
	public function multiKeyExists(array $arr, $key) {
337
		// is in base array?
338
		if (array_key_exists($key, $arr)) {
339
			return true;
340
		}
341
		// check arrays contained in this array
342
		foreach ($arr as $element) {
343
			if (is_array($element)) {
344
				if ($this->multiKeyExists($element, $key)) {
345
					return true;
346
				}
347
			}
348
		}
349
		return false;
350
	}
351
	
352
	/**
353
	* Returns list of available locales
354
	*
355
	* @return array
356
	 */
357
	public function listLocaleDir()
358
	{
359
		$result = array('en');
360
		if (!is_dir('./locale')) {
361
			return $result;
362
		}
363
		$handle = @opendir('./locale');
364
		if ($handle === false) return $result;
365
		while (false !== ($file = readdir($handle))) {
366
			$path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo';
367
			if ($file != "." && $file != ".." && @file_exists($path)) {
368
				$result[] = $file;
369
			}
370
		}
371
		closedir($handle);
372
		return $result;
373
	}
374
375
	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
376
		global $globalMapRefresh;
377
		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
378
		$r = 6378;
379
		$latitude = deg2rad($latitude);
380
		$longitude = deg2rad($longitude);
381
		$bearing = deg2rad($heading); 
382
		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
383
		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
384
		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
385
	}
386
	
387
	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
388
		// distance in meter
389
		$R = 6378.14;
390
		$latitude1 = $latitude * (M_PI/180);
391
		$longitude1 = $longitude * (M_PI/180);
392
		$brng = $bearing * (M_PI/180);
393
		$d = $distance;
394
395
		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
396
		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
397
398
		$latitude2 = $latitude2 * (180/M_PI);
399
		$longitude2 = $longitude2 * (180/M_PI);
400
401
		$flat = round ($latitude2,6);
402
		$flong = round ($longitude2,6);
403
/*
404
		$dx = $distance*cos($bearing);
405
		$dy = $distance*sin($bearing);
406
		$dlong = $dx/(111320*cos($latitude));
407
		$dlat = $dy/110540;
408
		$flong = $longitude + $dlong;
409
		$flat = $latitude + $dlat;
410
*/
411
		return array('latitude' => $flat,'longitude' => $flong);
412
	}
413
414
	/**
415
	 * GZIPs a file on disk (appending .gz to the name)
416
	 *
417
	 * From http://stackoverflow.com/questions/6073397/how-do-you-create-a-gz-file-using-php
418
	 * Based on function by Kioob at:
419
	 * http://www.php.net/manual/en/function.gzwrite.php#34955
420
	 * 
421
	 * @param string $source Path to file that should be compressed
422
	 * @param integer $level GZIP compression level (default: 9)
423
	 * @return string New filename (with .gz appended) if success, or false if operation fails
424
	 */
425
	public function gzCompressFile($source, $level = 9){ 
426
		$dest = $source . '.gz'; 
427
		$mode = 'wb' . $level; 
428
		$error = false; 
429
		if ($fp_out = gzopen($dest, $mode)) { 
430
			if ($fp_in = fopen($source,'rb')) { 
431
				while (!feof($fp_in)) 
432
					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
433
				fclose($fp_in); 
434
			} else {
435
				$error = true; 
436
			}
437
			gzclose($fp_out); 
438
		} else {
439
			$error = true; 
440
		}
441
		if ($error)
442
			return false; 
443
		else
444
			return $dest; 
445
	} 
446
	
447
	public function remove_accents($string) {
448
		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
449
		$chars = array(
450
		    // Decompositions for Latin-1 Supplement
451
		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
452
		    chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
453
		    chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
454
		    chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
455
		    chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
456
		    chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
457
		    chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
458
		    chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
459
		    chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
460
		    chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
461
		    chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
462
		    chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
463
		    chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
464
		    chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
465
		    chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
466
		    chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
467
		    chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
468
		    chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
469
		    chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
470
		    chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
471
		    chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
472
		    chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
473
		    chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
474
		    chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
475
		    chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
476
		    chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
477
		    chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
478
		    chr(195).chr(191) => 'y',
479
		    // Decompositions for Latin Extended-A
480
		    chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
481
		    chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
482
		    chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
483
		    chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
484
		    chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
485
		    chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
486
		    chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
487
		    chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
488
		    chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
489
		    chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
490
		    chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
491
		    chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
492
		    chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
493
		    chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
494
		    chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
495
		    chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
496
		    chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
497
		    chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
498
		    chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
499
		    chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
500
		    chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
501
		    chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
502
		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
503
		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
504
		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
505
		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
506
		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
507
		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
508
		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
509
		    chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
510
		    chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
511
		    chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
512
		    chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
513
		    chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
514
		    chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
515
		    chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
516
		    chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
517
		    chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
518
		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
519
		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
520
		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
521
		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
522
		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
523
		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
524
		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
525
		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
526
		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
527
		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
528
		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
529
		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
530
		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
531
		    chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
532
		    chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
533
		    chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
534
		    chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
535
		    chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
536
		    chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
537
		    chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
538
		    chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
539
		    chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
540
		    chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
541
		    chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
542
		    chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
543
		    chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
544
		);
545
		$string = strtr($string, $chars);
546
		return $string;
547
	}
548
	
549
	/*
550
	* Extract int from a string
551
	* Come from http://php.net/manual/fr/function.intval.php comment by michiel ed thalent nl
552
	*
553
	* @param String Input string
554
	* @return Integer integer from the string
555
	*/
556
	public function str2int($string, $concat = false) {
557
		$length = strlen($string);    
558
		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
559
			if (is_numeric($string[$i]) && $concat_flag) {
560
				$int .= $string[$i];
561
			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
562
				$concat_flag = false;
563
			}
564
		}
565
		return (int) $int;
566
	}
567
	
568
	function create_socket($host, $port, &$errno, &$errstr) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
569
		$ip = gethostbyname($host);
570
		$s = socket_create(AF_INET, SOCK_STREAM, 0);
571
		$r = @socket_connect($s, $ip, $port);
572
		if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n";
573
		if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
574
			return $s;
575
		}
576
		$errno = socket_last_error($s);
577
		$errstr = socket_strerror($errno);
578
		socket_close($s);
579
		return false;
580
	}
581
582
	function create_socket_udp($host, $port, &$errno, &$errstr) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
583
		$ip = gethostbyname($host);
584
		$s = socket_create(AF_INET, SOCK_DGRAM, 0);
585
		$r = @socket_bind($s, $ip, $port);
586
		if ($r || socket_last_error() == 114 || socket_last_error() == 115) {
587
			return $s;
588
		}
589
		$errno = socket_last_error($s);
590
		$errstr = socket_strerror($errno);
591
		socket_close($s);
592
		return false;
593
	}
594
}
595
?>