Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:14:14+00:00 2026-06-01T10:14:14+00:00

Prerequisites: hunspell and php5 . Test code from bash: user@host ~/ $ echo ‘sagadījās’

  • 0

Prerequisites: hunspell and php5.

Test code from bash:

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

– works properly.

Test code (test.php):

$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;

returns

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

It seems that shell_exec cannot handle utf-8 correctly, or maybe some additional encoding/decoding is needed?

EDIT: I had to use en_US.utf-8 to get valid data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:14:15+00:00Added an answer on June 1, 2026 at 10:14 am

    Try this code:

    <?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:\n";
      while (!feof($stdOut)) echo fgets($stdOut);
      fclose($stdOut);
    
      // Display raw errors
      echo "\n\nSTDERR:\n";
      while (!feof($stdErr)) echo fgets($stdErr);
      fclose($stdErr);
    
      // Close the process pointer
      proc_close($process);
    
    ?>
    

    Don’t forget to verify that the encoding of the file (and therefore the encoding of the data you are passing) actually is UTF-8 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a multi layer nested form User->Tasks->Prerequisites and in the same form User->Tasks->Location
What are the prerequisites (or steps) to host a WCF REST based service on
From section 4.14 Generating Prerequisites Automatically of GNU make manual %.d: %.c @set -e;
Prerequisites: Android 2.2 emulator. I have a perfectly working Java code which is compiled
I am using gcc -MM to generate prerequisites of dependencies rules for compiling source
VS2008's Setup Projects have a handful of built-in prerequisites (e.g. .NETfx version, VSTO, PowerPacks)
I have a WiX installer which installs .Net 4 and SQL as prerequisites. All
I have this code: <INPUT type=button value=Pre-Requisites onClick=window.open('pre_requisites.php','pre-requisites','width=670px,height=470px,left=0px,top=100px,screenX=0,screenY=100')> It is use to open a
Prerequisites: In MS Access 2010 create the following tables: CREATE TABLE ATBL(ID INT); INSERT
I installed all the prerequisites for Android development . I created a virtual device

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.