Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. user@host ~/ $ echo 'sagadījās' | hunspell -d lv_LV,en_US
  2. Hunspell 1.2.14
  3. + sagadīties
  4.  
  5. $encoding = "lv_LV.utf-8";
  6.  
  7. setlocale(LC_CTYPE, $encoding); // test
  8. putenv('LANG='.$encoding); // and another test
  9.  
  10. $raw_response = shell_exec("LANG=$encoding; echo 'sagadījās' | hunspell -d lv_LV,en_US");
  11.  
  12. echo $raw_response;
  13.  
  14. Hunspell 1.2.14
  15. & sagad 5 0: tagad, sagad?ties, sagaudo, sagand?, sagar?o
  16. *
  17. *
  18.  
  19. <?php
  20.  
  21. // The word we are checking
  22. $subject = 'sagadījās';
  23.  
  24. // We want file pointers for all 3 std streams
  25. $descriptors = array (
  26. 0 => array("pipe", "r"), // STDIN
  27. 1 => array("pipe", "w"), // STDOUT
  28. 2 => array("pipe", "w") // STDERR
  29. );
  30.  
  31. // An environment variable
  32. $env = array(
  33. 'LANG' => 'lv_LV.utf-8'
  34. );
  35.  
  36. // Try and start the process
  37. if (!is_resource($process = proc_open('hunspell -d lv_LV,en_US', $descriptors, $pipes, NULL, $env))) {
  38. die("Could not start Hunspell!");
  39. }
  40.  
  41. // Put pipes into sensibly named variables
  42. $stdIn = &$pipes[0];
  43. $stdOut = &$pipes[1];
  44. $stdErr = &$pipes[2];
  45. unset($pipes);
  46.  
  47. // Write the data to the process and close the pipe
  48. fwrite($stdIn, $subject);
  49. fclose($stdIn);
  50.  
  51. // Display raw output
  52. echo "STDOUT:n";
  53. while (!feof($stdOut)) echo fgets($stdOut);
  54. fclose($stdOut);
  55.  
  56. // Display raw errors
  57. echo "nnSTDERR:n";
  58. while (!feof($stdErr)) echo fgets($stdErr);
  59. fclose($stdErr);
  60.  
  61. // Close the process pointer
  62. proc_close($process);
  63.  
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement