&lt;?php $str='表/test.zip'; $str = mb_convert_encoding($str,"SJIS−win","UTF−8"); readfile(str); ?&gt;   I got error with character 表. Error message is:  Warning: readfile(•\/test.zip): failed to open stream: No such file or directory in check.php on line 22 •\/test.zip   Of course 表/test.zip had already existed. I tried with other character except for text 表, all were OK, did NOT have any error.  Does anyone have any solution? Thank you very much for your help.  Note: It is not error about name of file, but error about name of path, name of folder is in JP. It is difference with
123297
I have the following code  &lt;?php if ($handle = opendir('C:/xampp/htdocs/movies')) {     while (false !== ($file = readdir($handle))) {         if ($file != "." &amp;&amp; $file != "..") {             echo $file."&lt;br /&gt;\n";         }     }     closedir($handle); } ?&gt;   When it does have mb language such as japanese, it doesn't display properly instead it display like kyuukyoku Choujin R ?????~? rather then kyuukyoku Choujin R 究極超人あ～る  Anyway to make it display the correct name or make it still download-able by others?  Thanks for helping me :)
52153
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example), grabs the episode name (from the www.thetvdb.com API) and automatically renames them into something nicer (Show Name - [01x02].avi)  The script works fine, that is until you try and use it on files that have Unicode show-names (something I never really thought about, since all the files I have are English, so mostly pretty-much all fall within [a-zA-Z0-9'\-])  How can I allow the regular expressions to match accented characters and the likes? Currently the regex's config section looks like..  config['valid_filename_chars'] = """0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@£$%^&amp;*()_+=-[]{}"'.,&lt;&gt;`~? """ config['valid_filename_chars_regex'] = re.escape(config['valid_filename_chars'])  config['name_parse'] = [     # foo_[s01]_[e01]     re.compile('''^([%s]+?)[ \._\-]\[[Ss]([0-9]+?)\]_\[[Ee]([0-9]+?)\]?[^\\/]*$'''% (config['valid_filename_chars_regex'])),     # foo.1x09*     re.compile('''^([%s]+?)[ \._\-]\[?([0-9]+)x([0-9]+)[^\\/]*$''' % (config['valid_filename_chars_regex'])),     # foo.s01.e01, foo.s01_e01     re.compile('''^([%s]+?)[ \._\-][Ss]([0-9]+)[\.\- ]?[Ee]([0-9]+)[^\\/]*$''' % (config['valid_filename_chars_regex'])),     # foo.103*     re.compile('''^([%s]+)[ \._\-]([0-9]{1})([0-9]{2})[\._ -][^\\/]*$''' % (config['valid_filename_chars_regex'])),     # foo.0103*     re.compile('''^([%s]+)[ \._\-]([0-9]{2})([0-9]{2,3})[\._ -][^\\/]*$''' % (config['valid_filename_chars_regex'])), ]
94186
I want to read UTF-8 input in Perl, no matter if it comes from the standard input or from a file, using the diamond operator: while(&lt;&gt;){...}.  So my script should be callable in these two ways, as usual, giving the same output:  ./script.pl utf8.txt cat utf8.txt | ./script.pl   But the outputs differ! Only the second call (using cat) seems to work as designed, reading UTF-8 properly. Here is the script:  #!/usr/bin/perl -w  binmode STDIN, ':utf8'; binmode STDOUT, ':utf8';  while(&lt;&gt;){     my @chars = split //, $_;     print "$_\n" foreach(@chars); }   How can I make it read UTF-8 correctly in both cases? I would like to keep using the diamond operator &lt;&gt; for reading, if possible.  EDIT:   I realized I should probably describe the different outputs. My input file contains this sequence: a\xCA\xA7b. The method with cat correctly outputs:  a \xCA\xA7 b   But the other method gives me this:  a \xC3\x8A \xC2\xA7 b
13947
I am open a file in vi:  vi index.php   Here the problem is: when I press the down arrow and it prints 'B'. Why it prints 'B'?
34476
With reference to the following thread:   What is the best way to programatically determine the correct charset encoding of an inputstream/file ?  I have tried using the following:  File in =  new File(args[0]); InputStreamReader r = new InputStreamReader(new FileInputStream(in)); System.out.println(r.getEncoding());   But on a file which I know to be encoded with ISO8859_1 the above code yields ASCII, which is not correct, and does not allow me to correctly render the content of the file back to the console.
122931
I have a file named /tmp/urlFile where each line represents a url. I am trying to read from the file as follows:  cat "/tmp/urlFile" | while read url do     echo $url done   If the last line doesn't end with a newline character, that line won't be read. I was wondering why?   Is it possible to read all the lines, regardless if they are ended with a new line or not?
52835
fopen is failing when I try to read in a very moderately sized file in PHP.  A 6 meg file makes it choke, though smaller files around 100k are just fine.  i've read that it is sometimes necessary to recompile PHP with the -D_FILE_OFFSET_BITS=64 flag in order to read files over 20 gigs or something ridiculous, but shouldn't I have no problems with a 6 meg file?  Eventually we'll want to read in files that are around 100 megs, and it would be nice be able to open them and then read through them line by line with fgets as I'm able to do with smaller files.  What are your tricks/solutions for reading and doing operations on very large files in PHP?  Update:  Here's an example of a simple codeblock that fails on my 6 meg file - PHP doesn't seem to throw an error, it just returns false.  Maybe I'm doing something extremely dumb?  $rawfile = "mediumfile.csv";  if($file = fopen($rawfile, "r")){     fclose($file); } else {   echo "fail!"; }   Another update:  Thanks all for your help, it did turn out to be something incredibly dumb - a permissions issue.  My small file inexplicably had read permissions when the larger file didn't.  Doh!
108831
My problem is that, I can not give name of my folder or file with special characters like \ / : * ? " &lt; > | in windows based O.S. This is very important for me, that giving name of file/folder which contain this type of characters.  I already search and refer so many site,for this problems but all are hopeless. I also read Microsoft support page, they suggest use other characters. This is its link,    I already try Alt button + ASCII code number of this type of special characters, from numpad key, just example rename file/folder and press Alt+60 (for &lt; characters) Still it giving message that, A filename cannot contain any of the following characters: \ / : * ? " &lt; > |   Suggest me suitable solution so that I can give name of my file/folder with this type of special characters.
76738
I have a webserver administration question. In this website:   All PHP generated pages contain the following line:  &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /&gt;   But this is somehow disregarded probably via the php-apache processing and the page displays in browsers with an UTF-8 header. As a result of that question marks (�) are shown in the page text instead of accented characters (éáöőóüűúí). I tested this in Firefox, IE, Chrome and Seamonkey.  The strangest in this phenomenon, that this symptom started only yesterday, after I upgraded my server to Debian 8.0 Jessie from 7.0 Wheezy. During the upgrade I also upgraded all other packages as well, including apache, php, and so on, and selected "yes" for overwriting config files with factory default ones. After this I fine-tuned my config files to have everything the way I like, but I did not find a way to fix this. Before the upgrade, the page displayed just fine.  Here is a screenshot, where you can see that Firefox sees the "charset=iso-8859-2" definition, but still displays the page with UTF-8 encoding.    My suspicion is, that this is a server configuration issue, but it could also be, that one part of the processing component (Apache, php) changed due to the upgrade in some way, resulting this strange behavior. The problem is, I can't pinpoint, what could possibly cause this problem.  Can anyone solve this mistery? What could be possibly going wrong during the processing of the page?
91060
When I do hexdump filename.txt I get the following as output:  00000000 ac5a 5afb c08d 5d15 26d0 2491 e8c9 8917 00000010    When I do &lt;?= bin2hex(file_get_contents('filename.txt')); ?&gt; I get this:  5aacfb5a8dc0155dd0269124c9e81789   So why is hexdump suggesting the contents should be ac5a5afbc08d5d1526d02491e8c98917 when PHP is suggesting they ought to be 5aacfb5a8dc0155dd0269124c9e81789? Am I just not interpreting the output of hexdump correctly?
74518
I have an application which sends a POST request to the VB forum software and logs someone in (without setting cookies or anything).  Once the user is logged in I create a variable that creates a path on their local machine.  c:\tempfolder\date\username  The problem is that some usernames are throwing "Illegal chars" exception. For example if my username was mas|fenix it would throw an exception..  Path.Combine( _         Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), _   DateTime.Now.ToString("ddMMyyhhmm") + "-" + form1.username)   I don't want to remove it from the string, but a folder with their username is created through FTP on a server. And this leads to my second question. If I am creating a folder on the server can I leave the "illegal chars" in? I only ask this because the server is Linux based, and I am not sure if Linux accepts it or not.  EDIT: It seems that URL encode is NOT what I want.. Here's what I want to do:  old username = mas|fenix new username = mas%xxfenix   Where %xx is the ASCII value or any other value that would easily identify the character.
77905
I downloaded  to my webserver and unzipped it.  It contains a folder named -. I assumed I know how to deal with that, but I don't.  I tried cd -- -, but that doesn't have the desired effect. Using quotes doesn't seem to affect it either. I put slashes all over the place, to no avail.  What's the proper way to change into this folder?
17694
I can read the MySQL documentation and it's pretty clear. But, how does one decide which character set to use? On what data does collation have an effect?  I'm asking for an explanation of the two and how to choose them.
40564
I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?  One method I found was to write the content to a tmp file and then ...  $f = gzopen($filename,"r"); $content = gzread($filename,250000); gzclose($f);   .... but man, there's got to be a better way.  Edit: This isn't a file, but a gzipped html page returned by a web server.
95793
Important note: I'm using Cygwin    I retrieve JSON from a file that I alter before sending it to a server using curl. By now everything is ok except one thing, when the server receive the JSON, every special characters (with accents, etc) aren't well encoded. I suppose this was due to the fact that my JSON wasn't encoded in UTF-8 before being sent but I don't manage to convert it.  Here is the code:  sed -i 's/\r//g' $file fileContent=`cat $file`  result=$(jq -c -j ".docs[$docIndex] + { \"_rev\": \"$rev\" }"&lt;&lt;&lt;"$fileContent")            result="{\"docs\":[$result]}"  result=$result | sed 's/\r//g' result=$result | iconv -t "UTF-8" s=$(curl -H "Content-Type: application/json; charset=UTF-8" -H "Cache-Control: no-cache" -d "$result" $2/$3/_bulk_docs --silent)   My bash script and my JSON files are both encoded in UTF-8. My LANG variable seems to be UTF-8. I checked with this: [[ $LANG =~ UTF-8$ ]] &amp;&amp; echo "Uses UTF-8 encoding.."  Any idea?    Update  Here is the full script:  #!/bin/bash  # $1 = directory containing JSON files # $2 = server url (+ port) # $3 = database name  #Loop on every file of the given directory for file in "$1"/*; do      #Try to insert every document of a specific JSON file and retrieve their status (200 = OK; 409 = conflict)     allStatus=$(curl -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-binary "@$file" $2/$3/_bulk_docs --silent | jq '.[] |.status' | tr -d '\r')     docIndex=0      #Loop on every status (one status = one document)     while IFS=' ' read -ra statusArray; do       for status in "${statusArray[@]}"; do          #Remove unwanted windows characters of the file         sed -i 's/\r//g' $file         fileContent=`cat $file`          #Retrieve the id of the current document         id=`jq -r -j ".docs[$docIndex]._id"&lt;&lt;&lt;"$fileContent" | tr -d '\r'`          if [ "$status" = "409" ]         then              #Retrieve the revision of the current document and add it to the document              rev=$(curl -X GET --header 'Accept: application/json' $2/$3/$id?revs=true --silent | jq -r -j '._rev' | tr -d '\r')             result=$(jq -c -j ".docs[$docIndex] + { \"_rev\": \"$rev\" }"&lt;&lt;&lt;"$fileContent")              #Wrap the document inside {"docs":[]}             result="{\"docs\":[$result]}"              #Remove unwanted windows characters before sending the document (again)             result=$result | sed 's/\r//g'             result=$result | iconv -t "UTF-8"             s=$(curl -H "Content-Type: application/json; charset=UTF-8" -H "Cache-Control: no-cache" -d "$result" $2/$3/_bulk_docs --silent)              #Echo result             echo $s         else           #Status should be 200.           echo 'status: '$status ' - ' $id         fi          docIndex=$((docIndex+1))        done     done &lt;&lt;&lt; "$allStatus" done   This script aims to upsert documents inside a NoSQL database. If first try to insert and if if fails it retrieves a property (the revision) of the document, append to it and then retry once.  I know this script could be improved but this is my first bash script and it won't be used in production (only for testing, etc.).
7977
I'm in the process of making my PHP site Unicode-aware. I'm wondering if anyone has experience with the mbstring.func_overload setting, which replaces the normal string functions (e.g. strlen) with their multi-byte equivalents (mb_strlen). There aren't any comments on the PHP manual page.  Are there any potential problems that I should be aware of? Any cases where calling the multi-byte version is a bad idea?  I suppose one example would be functions that deal with encryption, since they may expect to deal with strings of bytes, rather than strings of characters.  Also, the manual page includes a note: "It is not recommended to use the function overloading option in the per-directory context, because it's not confirmed yet to be stable enough in a production environment and may lead to undefined behaviour."  Does that mean that it's not stable in a per-directory context, or it's generally not stable? The wording is unclear.
41971
I have a bash script which enumerates through every *.php file in a directory and applies iconv to it. This gets output in STDOUT.   Since adding the -o parameter ( in my experience ) actually writes a blank file probably before the conversion takes place, how can I adjust my script so it does the conversion, then overwrites the input file?  for file in *.php do     iconv -f cp1251 -t utf8 "$file" done