Completed
Push — master ( cc50d0...0f8c33 )
by Yannick
09:46
created

Common::getData()   F

Complexity

Conditions 19
Paths 2592

Size

Total Lines 66
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 51
nc 2592
nop 8
dl 0
loc 66
rs 2.7576
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
		curl_close($ch);
71
		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
72
			echo "Cloudflare Detected\n";
73
			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
74
			$useragent = UAgent::random();
75
			cloudflare::useUserAgent($useragent);
76
			if ($clearanceCookie = cloudflare::bypass($url)) {
77
				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
78
			}
79
		} else {
80
		    return $result;
81
		}
82
	}
83
	
84
	private function curlResponseHeaderCallback($ch, $headerLine) {
85
		//global $cookies;
86
		$cookies = array();
87
		if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1)
88
			$cookies[] = $cookie;
89
		return strlen($headerLine); // Needed by curl
90
	}
91
92
	public static function download($url, $file, $referer = '') {
93
		global $globalDebug;
94
		$fp = fopen($file, 'w');
95
		$ch = curl_init();
96
		curl_setopt($ch, CURLOPT_URL, $url);
97
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
98
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
99
		if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer);
100
		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');
101
		curl_setopt($ch, CURLOPT_FILE, $fp);
102
		curl_exec($ch);
103
		if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch);
104
		curl_close($ch);
105
		fclose($fp);
106
	}
107
	
108
	/**
109
	* Convert a HTML table to an array
110
	* @param String $data HTML page
111
	* @return Array array of the tables in HTML page
112
	*/
113
	public function table2array($data) {
114
		if (!is_string($data)) return array();
115
		if ($data == '') return array();
116
		$html = str_get_html($data);
117
		if ($html === false) return array();
118
		$tabledata=array();
119
		foreach($html->find('tr') as $element)
120
		{
121
			$td = array();
122
			foreach( $element->find('th') as $row)
123
			{
124
				$td [] = trim($row->plaintext);
125
			}
126
			$td=array_filter($td);
127
			$tabledata[] = $td;
128
129
			$td = array();
130
			$tdi = array();
131
			foreach( $element->find('td') as $row)
132
			{
133
				$td [] = trim($row->plaintext);
134
				$tdi [] = trim($row->innertext);
135
			}
136
			$td=array_filter($td);
137
			$tdi=array_filter($tdi);
138
			$tabledata[]=array_merge($td,$tdi);
139
		}
140
		$html->clear();
141
		unset($html);
142
		return(array_filter($tabledata));
143
	}
144
	
145
	/**
146
	* Convert <p> part of a HTML page to an array
147
	* @param String $data HTML page
148
	* @return Array array of the <p> in HTML page
149
	*/
150
	public function text2array($data) {
151
		$html = str_get_html($data);
152
		if ($html === false) return array();
153
		$tabledata=array();
154
		foreach($html->find('p') as $element)
155
		{
156
			$tabledata [] = trim($element->plaintext);
157
		}
158
		$html->clear();
159
		unset($html);
160
		return(array_filter($tabledata));
161
	}
162
163
	/**
164
	* Give distance between 2 coordonnates
165
	* @param Float $lat latitude of first point
166
	* @param Float $lon longitude of first point
167
	* @param Float $latc latitude of second point
168
	* @param Float $lonc longitude of second point
169
	* @param String $unit km else no unit used
170
	* @return Float Distance in $unit
171
	*/
172
	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
173
		if ($lat == $latc && $lon == $lonc) return 0;
174
		$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;
175
		if ($unit == "km") {
176
			return round($dist * 1.609344);
177
		} elseif ($unit == "m") {
178
			return round($dist * 1.609344 * 1000);
179
		} elseif ($unit == "mile" || $unit == "mi") {
180
			return round($dist);
181
		} elseif ($unit == "nm") {
182
			return round($dist*0.868976);
183
		} else {
184
			return round($dist);
185
		}
186
	}
187
188
	/**
189
	* Check is distance realistic
190
	* @param int $timeDifference the time between the reception of both messages
191
	* @param float $distance distance covered
192
	* @return whether distance is realistic
193
	*/
194
	public function withinThreshold ($timeDifference, $distance) {
195
		$x = abs($timeDifference);
196
		$d = abs($distance);
197
		if ($x == 0 || $d == 0) return true;
198
		// may be due to Internet jitter; distance is realistic
199
		if ($x < 0.7 && $d < 2000) return true;
200
		else return $d/$x < 1500*0.27778; // 1500 km/h max
201
	}
202
203
204
	// Check if an array is assoc
205
	public function isAssoc($array)
206
	{
207
		return ($array !== array_values($array));
208
	}
209
210
	public function isInteger($input){
211
	    return(ctype_digit(strval($input)));
212
	}
213
214
215
	public function convertDec($dms,$latlong) {
216
		if ($latlong == 'latitude') {
217
			$deg = substr($dms, 0, 2);
218
			$min = substr($dms, 2, 4);
219
		} else {
220
			$deg = substr($dms, 0, 3);
221
			$min = substr($dms, 3, 5);
222
		}
223
		return $deg+(($min*60)/3600);
224
	}
225
	
226
	/**
227
	* Copy folder contents
228
	* @param       string   $source    Source path
229
	* @param       string   $dest      Destination path
230
	* @return      bool     Returns true on success, false on failure
231
	*/
232
	public function xcopy($source, $dest)
233
	{
234
		$files = glob($source.'*.*');
235
		foreach($files as $file){
236
			$file_to_go = str_replace($source,$dest,$file);
237
			copy($file, $file_to_go);
238
		}
239
		return true;
240
	}
241
	
242
	/**
243
	* Check if an url exist
244
	* @param	String $url url to check
245
	* @return	bool Return true on succes false on failure
246
	*/
247
	public function urlexist($url){
248
		$headers=get_headers($url);
249
		return stripos($headers[0],"200 OK")?true:false;
250
	}
251
	
252
	/**
253
	* Convert hexa to string
254
	* @param	String $hex data in hexa
255
	* @return	String Return result
256
	*/
257
	public function hex2str($hex) {
258
		$str = '';
259
		$hexln = strlen($hex);
260
		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
261
		return $str;
262
	}
263
	
264
	
265
	public function getHeading($lat1, $lon1, $lat2, $lon2) {
266
		//difference in longitudinal coordinates
267
		$dLon = deg2rad($lon2) - deg2rad($lon1);
268
		//difference in the phi of latitudinal coordinates
269
		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
270
		//we need to recalculate $dLon if it is greater than pi
271
		if(abs($dLon) > pi()) {
272
			if($dLon > 0) {
273
				$dLon = (2 * pi() - $dLon) * -1;
274
			} else {
275
				$dLon = 2 * pi() + $dLon;
276
			}
277
		}
278
		//return the angle, normalized
279
		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
280
	}
281
	
282
	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) {
283
		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
284
		$a = -($lon2-$lon1);
285
		$b = $lat2 - $lat1;
286
		$c = -($a*$lat1+$b*$lon1);
287
		$d = $a*$lat3+$b*$lon3+$c;
288
		if ($d > -$approx && $d < $approx) return true;
289
		else return false;
290
	}
291
	
292
	public function array_merge_noappend() {
293
		$output = array();
294
		foreach(func_get_args() as $array) {
295
			foreach($array as $key => $value) {
296
				$output[$key] = isset($output[$key]) ?
297
				array_merge($output[$key], $value) : $value;
298
			}
299
		}
300
		return $output;
301
	}
302
	
303
304
	public function arr_diff($arraya, $arrayb) {
305
		foreach ($arraya as $keya => $valuea) {
306
			if (in_array($valuea, $arrayb)) {
307
				unset($arraya[$keya]);
308
			}
309
		}
310
		return $arraya;
311
	}
312
313
	/*
314
	* Check if a key exist in an array
315
	* Come from http://stackoverflow.com/a/19420866
316
	* @param Array array to check
317
	* @param String key to check
318
	* @return Bool true if exist, else false
319
	*/
320
	public function multiKeyExists(array $arr, $key) {
321
		// is in base array?
322
		if (array_key_exists($key, $arr)) {
323
			return true;
324
		}
325
		// check arrays contained in this array
326
		foreach ($arr as $element) {
327
			if (is_array($element)) {
328
				if ($this->multiKeyExists($element, $key)) {
329
					return true;
330
				}
331
			}
332
		}
333
		return false;
334
	}
335
	
336
	/**
337
	* Returns list of available locales
338
	*
339
	* @return array
340
	 */
341
	public function listLocaleDir()
342
	{
343
		$result = array('en');
344
		if (!is_dir('./locale')) {
345
			return $result;
346
		}
347
		$handle = @opendir('./locale');
348
		if ($handle === false) return $result;
349
		while (false !== ($file = readdir($handle))) {
350
			$path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo';
351
			if ($file != "." && $file != ".." && @file_exists($path)) {
352
				$result[] = $file;
353
			}
354
		}
355
		closedir($handle);
356
		return $result;
357
	}
358
359
	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
360
		global $globalMapRefresh;
361
		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
362
		$r = 6378;
363
		$latitude = deg2rad($latitude);
364
		$longitude = deg2rad($longitude);
365
		$bearing = deg2rad($heading); 
366
		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
367
		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
368
		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
369
	}
370
	
371
	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
372
		// distance in meter
373
		$R = 6378.14;
374
		$latitude1 = $latitude * (M_PI/180);
375
		$longitude1 = $longitude * (M_PI/180);
376
		$brng = $bearing * (M_PI/180);
377
		$d = $distance;
378
379
		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
380
		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
381
382
		$latitude2 = $latitude2 * (180/M_PI);
383
		$longitude2 = $longitude2 * (180/M_PI);
384
385
		$flat = round ($latitude2,6);
386
		$flong = round ($longitude2,6);
387
/*
388
		$dx = $distance*cos($bearing);
389
		$dy = $distance*sin($bearing);
390
		$dlong = $dx/(111320*cos($latitude));
391
		$dlat = $dy/110540;
392
		$flong = $longitude + $dlong;
393
		$flat = $latitude + $dlat;
394
*/
395
		return array('latitude' => $flat,'longitude' => $flong);
396
	}
397
398
	/**
399
	 * GZIPs a file on disk (appending .gz to the name)
400
	 *
401
	 * From http://stackoverflow.com/questions/6073397/how-do-you-create-a-gz-file-using-php
402
	 * Based on function by Kioob at:
403
	 * http://www.php.net/manual/en/function.gzwrite.php#34955
404
	 * 
405
	 * @param string $source Path to file that should be compressed
406
	 * @param integer $level GZIP compression level (default: 9)
407
	 * @return string New filename (with .gz appended) if success, or false if operation fails
408
	 */
409
	public function gzCompressFile($source, $level = 9){ 
410
		$dest = $source . '.gz'; 
411
		$mode = 'wb' . $level; 
412
		$error = false; 
413
		if ($fp_out = gzopen($dest, $mode)) { 
414
			if ($fp_in = fopen($source,'rb')) { 
415
				while (!feof($fp_in)) 
416
					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
417
				fclose($fp_in); 
418
			} else {
419
				$error = true; 
420
			}
421
			gzclose($fp_out); 
422
		} else {
423
			$error = true; 
424
		}
425
		if ($error)
426
			return false; 
427
		else
428
			return $dest; 
429
	} 
430
	
431
	public function remove_accents($string) {
432
		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
433
		$chars = array(
434
		    // Decompositions for Latin-1 Supplement
435
		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
436
		    chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
437
		    chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
438
		    chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
439
		    chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
440
		    chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
441
		    chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
442
		    chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
443
		    chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
444
		    chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
445
		    chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
446
		    chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
447
		    chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
448
		    chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
449
		    chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
450
		    chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
451
		    chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
452
		    chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
453
		    chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
454
		    chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
455
		    chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
456
		    chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
457
		    chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
458
		    chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
459
		    chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
460
		    chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
461
		    chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
462
		    chr(195).chr(191) => 'y',
463
		    // Decompositions for Latin Extended-A
464
		    chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
465
		    chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
466
		    chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
467
		    chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
468
		    chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
469
		    chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
470
		    chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
471
		    chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
472
		    chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
473
		    chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
474
		    chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
475
		    chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
476
		    chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
477
		    chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
478
		    chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
479
		    chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
480
		    chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
481
		    chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
482
		    chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
483
		    chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
484
		    chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
485
		    chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
486
		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
487
		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
488
		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
489
		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
490
		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
491
		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
492
		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
493
		    chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
494
		    chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
495
		    chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
496
		    chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
497
		    chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
498
		    chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
499
		    chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
500
		    chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
501
		    chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
502
		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
503
		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
504
		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
505
		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
506
		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
507
		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
508
		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
509
		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
510
		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
511
		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
512
		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
513
		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
514
		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
515
		    chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
516
		    chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
517
		    chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
518
		    chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
519
		    chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
520
		    chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
521
		    chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
522
		    chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
523
		    chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
524
		    chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
525
		    chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
526
		    chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
527
		    chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
528
		);
529
		$string = strtr($string, $chars);
530
		return $string;
531
	}
532
	
533
	/*
534
	* Extract int from a string
535
	* Come from http://php.net/manual/fr/function.intval.php comment by michiel ed thalent nl
536
	*
537
	* @param String Input string
538
	* @return Integer integer from the string
539
	*/
540
	public function str2int($string, $concat = false) {
541
		$length = strlen($string);    
542
		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
543
			if (is_numeric($string[$i]) && $concat_flag) {
544
				$int .= $string[$i];
545
			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
546
				$concat_flag = false;
547
			}
548
		}
549
		return (int) $int;
550
	}
551
}
552
?>