Code Duplication    Length = 35-41 lines in 2 locations

func/string.php 1 location

@@ 349-389 (lines=41) @@
346
 * @param	string	$encoding	Encoding of output string.
347
 * @return	string
348
 */
349
function Rfc2047Decode($str, $encoding = 'utf-8')
350
{
351
	// Find string encoding
352
	$ar = array();
353
	//preg_match_all('/=\?(.{3,13})\?[B|Q]\?([\/\d\w\=]*)\?\=/i', $str, $ar);
354
	preg_match_all('/=\?(.{3,13})\?([B|Q])\?([^\?]*)\?\=/i', $str, $ar);
355
	// 0 is all-string pattern, 1 is encoding, 2 is string to base64_decode
356
	$i = count($ar[0]);
357
	//var_dump($ar);
358
	if (0 < $i)
359
	{
360
		// Got match, process
361
		for ($j = 0; $j < count($i); $j++)
362
		{
363
			$s = '';
364
			if ('B' == strtoupper($ar[2][$j])) {
365
				// Decode base64 first
366
				$s = base64_decode($ar[3][$j]);
367
			}
368
			elseif ('Q' == strtoupper($ar[2][$j])) {
369
				// quoted-printable encoding ? its format like '=0D=0A'
370
				$s = quoted_printable_decode($ar[3][$j]);
371
			}
372
373
			// Then convert string to charset ordered
374
			if ($encoding != strtolower($ar[1][$j]))
375
				$s = mb_convert_encoding($s, $encoding, $ar[1][$j]);
376
377
			// Then replace into original string
378
			if (!empty($s))
379
				$str = str_replace($ar[0][$j], $s, $str);
380
		}
381
		//echo "$str \n";
382
		return $str;
383
	}
384
	else
385
	{
386
		// No match, return original string
387
		return $str;
388
	}
389
}
390
391
392
/**

src/Fwlib/Util/Algorithm/Rfc2047.php 1 location

@@ 25-59 (lines=35) @@
22
     * @param   string  $encoding
23
     * @return  string
24
     */
25
    public function decode($str, $encoding = 'utf-8')
26
    {
27
        // Find string encoding
28
        $ar = [];
29
        preg_match_all('/=\?(.{3,13})\?([B|Q])\?([^\?]*)\?\=/i', $str, $ar);
30
        // 0 is all-string pattern, 1 is encoding, 2 is string to base64_decode
31
        $i = count($ar[0]);
32
        if (0 < $i) {
33
            // Got match, process
34
            for ($j = 0; $j < count($i); $j++) {
35
                $s = '';
36
                if ('B' == strtoupper($ar[2][$j])) {
37
                    // Decode base64 first
38
                    $s = base64_decode($ar[3][$j]);
39
                } elseif ('Q' == strtoupper($ar[2][$j])) {
40
                    // quoted-printable encoding ? its format like '=0D=0A'
41
                    $s = quoted_printable_decode($ar[3][$j]);
42
                }
43
44
                // Then convert string to charset ordered
45
                if ($encoding != strtolower($ar[1][$j])) {
46
                    $s = mb_convert_encoding($s, $encoding, $ar[1][$j]);
47
                }
48
49
                // Then replace into original string
50
                if (!empty($s)) {
51
                    $str = str_replace($ar[0][$j], $s, $str);
52
                }
53
            }
54
            return $str;
55
        } else {
56
            // No match, return original string
57
            return $str;
58
        }
59
    }
60
61
62
    /**