Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 12
TStringEncoding
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 12
 convert2Utf8
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 6
 convert2Iso8859_1
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 6
1<?php
2/*
3 * Formdin Framework
4 * Copyright (C) 2012 Ministério do Planejamento
5 * Criado por Luís Eugênio Barbosa
6 * Essa versão é um Fork https://github.com/bjverde/formDin
7 *
8 * ----------------------------------------------------------------------------
9 * This file is part of Formdin Framework.
10 *
11 * Formdin Framework is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License version 3
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License version 3
21 * along with this program; if not,  see <http://www.gnu.org/licenses/>
22 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
23 * Fifth Floor, Boston, MA  02110-1301, USA.
24 * ----------------------------------------------------------------------------
25 * Este arquivo é parte do Framework Formdin.
26 *
27 * O Framework Formdin é um software livre; você pode redistribuí-lo e/ou
28 * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação
29 * do Software Livre (FSF).
30 *
31 * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA
32 * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou
33 * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português
34 * para maiores detalhes.
35 *
36 * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título
37 * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/>
38 * ou escreva para a Fundação do Software Livre (FSF) Inc.,
39 * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA.
40 */
41
42/**
43 * This class centralizes the encoding type detection and conversion. It is dependent on the mbstring module
44 * 
45 * Esse classe centraliza a detecção e conversão do tipo codificação do texto (encoding). É dependente do modulo mbstring e iconv
46 * 
47 * http://php.net/manual/pt_BR/mbstring.supported-encodings.php
48 * https://stackoverflow.com/questions/8233517/what-is-the-difference-between-iconv-and-mb-convert-encoding-in-php
49 * 
50 * @author bjverte
51 *
52 */
53class TStringEncoding {
54
55    /**
56     * 
57     * @param string $string
58     */
59    public static function convert2Utf8 ($string){
60        $target_encoding = "UTF-8";
61        $enconding = mb_detect_encoding ($string);
62        $result = $string;
63        if($enconding != "UTF-8"){
64            //$result = mb_convert_encoding($target_encoding, $enconding,$string);
65            $result = iconv ($enconding,$target_encoding,$string);
66        }
67        return $result;
68    }
69    
70    
71    public static function convert2Iso8859_1($string){
72        $target_encoding = "ISO-8859-1";
73        $enconding = mb_detect_encoding ($string);
74        $result = $string;
75        if($enconding != "ISO-8859-1"){
76            //$result = mb_convert_encoding($target_encoding, $enconding,$string);
77            $result = iconv ($enconding,$target_encoding,$string);
78        }
79        return $result;
80    }
81    
82}