0

Hi the problem is this: I'm reading a couple of server generated files (txt) via fopen and fgets PHP functions to assamble a pdf, in some cases the source file (txt) has some special tags for call another file and insert its content in the tag position, tag Example:

††PuntosSent††

I tried several ways and I'm not able to get the tag because of the † character. I've tried the following ways and none of them seem to work for replacing the tag or change the charater to a "readable one"

 str_replace ($this->doc_p_sent  = my custom text value) 

 $full_body = str_replace('††PuntosSent††', $this->doc_p_sent, $full_body);

change the character for anything else (also tried with \†)

$full_body = str_replace('†', '*', $full_body);

the most aproximate way I get this was with this (works for a var with the † but not with the text from the txt file)

iconv("UTF-8", "ISO-8859-1//TRANSLIT", $full_body)

this last one changes the † character for a + plus if I use it directly like this:

iconv("UTF-8", "ISO-8859-1//TRANSLIT", '††PuntosSent††')

I hope someone here can point me in the right direction because im getting insane wth this :P

Regards people

achedeuzot
  • 4,164
  • 4
  • 41
  • 56
Strife86
  • 1,135
  • 1
  • 10
  • 18

1 Answers1

0

Finally :) The only way this works was changing each line i read from the text file for its HEX equivalent and searching for a HEX pattern and replacing it for a "readable one"

I found this somewhere here

private function string_to_hex($string){
    $hex = '';
    for ($i=0; $i<strlen($string); $i++){
        $ord = ord($string[$i]);
        $hexCode = dechex($ord);
        $hex .= substr('0'.$hexCode, -2);
    }
    return strToUpper($hex);
}

and then replace the hex pattern

$line = utf8_encode($line);
$hex_line = str_replace('C286C286', '2B2B', $this->string_to_hex($line));

note: even the C286 hex value is not the actual charater i was loking for but i belive is his utf8-hex aproximation.

and finally convert the HEX string to a human redable string again

$line = $this->hex_to_string($hex_line);

private function hex_to_string($hex){
    $string='';
    for ($i=0; $i < strlen($hex)-1; $i+=2){
        $string .= chr(hexdec($hex[$i].$hex[$i+1]));
    }
    return $string;
}

it cost me a little performance...YES but nothing else seems to work :(

Strife86
  • 1,135
  • 1
  • 10
  • 18