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 6898567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:18:46+00:00 2026-05-27T07:18:46+00:00

If I type å in CMD, fgets stop waiting for more input and the

  • 0

If I type å in CMD, fgets stop waiting for more input and the loop runs until I press ctrl-c. If I type a “normal” characters like a-z0-9!?() it works as expected.

I run the code in CMD under Windows 7 with UTF-8 as charset (chcp 65001), the file is saved as UTF-8 without bom. I use PHP 5.3.5 (cli).

<?php

echo "ÅÄÖåäö work here.\n";

while(1)
{
    echo '> '. fgets(STDIN);
}

?>

If I change charset to chcp 1252 the loop doesn’t break when I type å and it print “> å” but the “ÅÄÖåäö work here” become “ÅÄÖåäö work here!”. And I know that I can change the file to ANSI, but then I can’t use special characters like ╠╦╗.

So why does fgets stop waiting for userinput after I have typed åäö?

And how can I fix this?

EDIT:

Also found a strange bug.
echo "öäåÅÄÖåäö work here! Or?".chr(10); -> ��äåÅÄÖåäö work here! Or? re! Or?.
If the first char in echo is å/ä/ö it print strange chars AND the end output duplicate’s with n - 1 char.. (n = number of åäö in the begining of the string).

Eg: echo "åäö 1234" -> ??äö 123434 and echo åäöåäö 1234 -> ??äöåäö 1234 1234.

EDIT2 (solved):

The problem was chcp 65001, now I use chcp 437 (chcp 437).
Big thanks to Timothy Martens!

  • 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-05-27T07:18:46+00:00Added an answer on May 27, 2026 at 7:18 am

    Possible solution:

    echo '>'; 
    $line = stream_get_line(STDIN, 999999, PHP_EOL);
    

    Notes:
    I was unable to reproduce your error using multiple versions of PHP.
    Using the following PHP version 5.3.8 gave me no issues

    PHP 5.3 (5.3.8)
    VC9 x86 Non Thread Safe (2011-Aug-23 12:26:18)
    Arcitechture is Win XP SP3 32 bit

    You might try upgrading PHP.

    I downloaded php-5.3.5-nts-Win32-VC6-x86 and was not able to reproduce your error, it works fine for me.

    Edit: Additionaly I typed the characters using my spanish keyboard.

    Edit2:

    CMD Command:

    chcp 437
    

    PHP Code:

    <?php
    $fp=fopen("php://stdin","r");
    while(1){
        $str =  fgets(STDIN);
        echo mb_detect_encoding($str)."\n";
        echo '>'.stream_get_line($fp,999999,"\n")."\n";
    }
    ?>
    

    Output:

    test
    ASCII
    test
    >test
    öïü
    
    öïü
    >öïü
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application is basically a shell which expects an input of type cmd [x]
On Windows, you can go to Run, type in cmd, press enter, and start
I execute the ftp.exe cmd through a C# System.Diagnostics.Process type. And I use the
Which type of input is least vulnerable to Cross-Site Scripting (XSS) and SQL Injection
Consider type like this one public interface IHaveGenericMethod { T1 Method<T1>(T1 parm); T2 Method<T1,T2>(T1
From cmd on windows, you can type start filename and an action will be
http://nanoc.stoneship.org/docs/3-getting-started/ I type nanoc create_site tutorial using cmd command line within a folder. It
Possible Duplicate: Set up Python on Windows to not type python in cmd When
When I type rails server in my CMD the server works and I can
Let's assume we have the following data type: data Cmd = Cmd0 Opcode |

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.