Problems encountered in YII2

2

First of all, I talk about my stage. I am using the SAP RFC library in YII2 where I am importing an SAP ERP table into my PHP program.

The problem is that when printing a variable that contains accents is not printing them correctly, it puts something like this 'librer # a'. When I see the format of the variable with mb_detect_encoding() it appears to me that it is of the ASCII type, I do not know if this helps in anything. I already tried with utf8_encode() and meta.
Any recommendation?

At the moment I only have in mind to do this on the side of ABAP, which has worked for me but it is unnecessary since it would be best to fix it on the PHP side.

REPLACE ALL OCCURRENCES OF REGEX:
'[á]' IN wa_header-justif WITH 'á',
'[é]' IN wa_header-justif WITH 'é',
'[í]' IN wa_header-justif WITH 'í',
'[ó]' IN wa_header-justif WITH 'ó',
'[ú]' IN wa_header-justif WITH 'ú'.

Thanks in advance!

    
asked by Annon 07.04.2016 в 16:33
source

2 answers

2

ASCII is a subset of UTF-8, so if a document is ASCII it is really UTF-8. Being ASCII a subset means that it does not support all the characters that exist, including the characters and the ñ. When analyzing the variable, the function returns ASCII since a word like "librer # a" all its characters is found in this table.

The other case to consider here is that 'collation' was defined in the structure of the source database. As I understand SAP uses SQL Server database engine and its collection by default is Latin1_General. A solution to try is in the php file where the impression is made, at the beginning it puts the following statement

header("Content-Type: text/html; charset=utf-8");

When you want to print the variable, use the following function:

print iconv("CP1252", "UTF-8", $nombre_de_variable);
    
answered by 08.04.2016 в 04:44
1
  

htmlentities ( string $string [, int $flags [, string $encoding [, bool $double_encode ]]])

     

Convert all applicable characters to HTML entities

The HTML entities are the ones you describe in the question: á É , ñ , etc.

$resultado = htmlentities( $texto, ENT_SUBSTITUTE );
    
answered by 18.08.2016 в 12:01