utf8_fix.php ➔ Utf8Fix()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 2
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
1
<?php
2
/*
3
 * @package		fwolflib
4
 * @copyright	Copyright 2006-2010, Fwolf
5
 * @author		Fwolf <[email protected]>
6
 * @since		2006-07-12
7
 */
8
9
10
require_once(dirname(__FILE__) . '/../fwolflib.php');
11
12
13
/*
14
 * Convert string like '_D0_D0_D0' to normal string
15
 * These string mostly gerenated by using unicode method to read gb2312 string in some software.
16
 *
17
 * @param	string	$in				string to be fixed
18
 * @param	boolean	$keep_gb2312	return gb2312 string instead of utf8 str
19
 * @return	string
20
 */
21
function Utf8Fix($in, $keep_gb2312=false)
22
{
23
	$out = '';
24
	for ($i=0; $i<strlen($in); $i++)
25
	{
26
		$c = $in{$i};
27
		if ('_' == $c)
28
		{
29
			//begin convert
30
			$out .= chr(hexdec($in{$i+1} . $in{$i+2}));
31
			$i += 2;
32
		}
33
		else
34
		{
35
			//copy original
36
			$out .= $c;
37
		}
38
	}
39
	if (false == $keep_gb2312)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
40
		$out = mb_convert_encoding($out, 'utf-8', 'gbk');
41
	return $out;
42
} // end of function Utf8Fix
43
44
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
45