English 中文(简体)
通过彩票-exec 和utf-8文本投入使用
原标题:Call a program via shell_exec with utf-8 text input

Prerequisites:hunspell and php5

ash子试验代码:

user@host ~/ $ echo  sagadījās  | hunspell -d lv_LV,en_US
Hunspell 1.2.14
+ sagadīties

- 适当开展工作。

测试法(测试):

$encoding = "lv_LV.utf-8";

setlocale(LC_CTYPE, $encoding); // test
putenv( LANG= .$encoding); // and another test

$raw_response = shell_exec("LANG=$encoding; echo  sagadījās  | hunspell -d lv_LV,en_US");

echo $raw_response;

回返

Hunspell 1.2.14
& sagad 5 0: tagad, sagad?ties, sagaudo, sagand?, sagar?o
*
*

Screenshot (could not post code with invalid characters): Hunspell php invalid characters

看来, she子不能正确处理ut子8,或者可能需要一些额外的编码/dec?

EDIT:我不得不用_US.utf-8获得有效数据。

最佳回答

颁布这一法典:

<?php

  // The word we are checking
  $subject =  sagadījās ;

  // We want file pointers for all 3 std streams
  $descriptors = array (
    0 => array("pipe", "r"),  // STDIN
    1 => array("pipe", "w"),  // STDOUT
    2 => array("pipe", "w")   // STDERR
  );

  // An environment variable
  $env = array(
     LANG  =>  lv_LV.utf-8 
  );

  // Try and start the process
  if (!is_resource($process = proc_open( hunspell -d lv_LV,en_US , $descriptors, $pipes, NULL, $env))) {
    die("Could not start Hunspell!");
  }

  // Put pipes into sensibly named variables
  $stdIn = &$pipes[0];
  $stdOut = &$pipes[1];
  $stdErr = &$pipes[2];
  unset($pipes);

  // Write the data to the process and close the pipe
  fwrite($stdIn, $subject);
  fclose($stdIn);

  // Display raw output
  echo "STDOUT:
";
  while (!feof($stdOut)) echo fgets($stdOut);
  fclose($stdOut);

  // Display raw errors
  echo "

STDERR:
";
  while (!feof($stdErr)) echo fgets($stdErr);
  fclose($stdErr);

  // Close the process pointer
  proc_close($process);

?>

Don tabe用于核实档案的编码(因此是你通过的数据的编码)实际上is UTF-8 ;-

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签