Stripping accents from characters as they pass through a stream and then written to file
| From: | Marc Guay | Date: | Mon, 14 Jan 2013 15:10:11 +0000 |
| Subject: | Stripping accents from characters as they pass through a stream and then written to file | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-320087@lists.php.net to get a copy of this message | ||
Hi folks,
As the subject states I am trying to convert accented characters to
their ASCII equivalents as they pass through a stream and then get
written to file by the called script but am not having any luck. Here
is my code:
main.php
--------------
$descriptors = array(
0 => array("pipe", "r"),
1 => array("pipe", "w")
);
// Create connection
$process = proc_open("php script.php", $descriptors, $pipes);
// Attach filter
stream_filter_append($pipes[0], 'convert.iconv.UTF-8/ASCII//TRANSLIT');
fwrite($pipes[0], "é");
... close stuff, etc ...
script.php
--------------
$fd = fopen('log.txt', "ab"); // I've tried with and without the binary
switch
$in = fopen("php://stdin", "r");
while (!feof($in)) {
$line = fgets($in);
fwrite($fd, $line);
}
... close stuff, etc ...
And the character in my log file is a question mark (?). The 2 php
files are encoded as UTF-8 and according to Notepad++ the log.txt file
is encoded in ANSI. Any thoughts?
Marc