Is there a way to read a file in a specific character encoding like UTF-16 using PHP's stream wrappers, in the same way I can read a base64-encoded file using php://filter/convert.base64-decode/resource=file.txt?
How To Read A File in php wrappers as utf-16
663 views Asked by Ali Saleh At
1
There are 1 answers
Related Questions in PHP
- How to add the dynamic new rows from my registration form in my database?
- Issue in payment form gateway
- How to create a facet for WP gridbuilder that displays both parent and child custom fields?
- Function in anonymous Laravel Blade component
- How to change woocomerce or full wordpress currency with value from USD to AUD
- General questions about creating a custom theme Moodle CMS
- How to add logging to an abstract class in php
- error 500 on IIS FastCGI but no clue despite multiple error loggings activated
- Composer installation fails and reverts ./composer.json and ./composer.lock to original content
- How to isolate PHP apps from each other on a local machine(Windows or Linux)?
- Laravel: Using belongsToMany relationship with MongoDB
- window.location.href redirects but is causing problems on the webpage
- Key provided is shorter than 256 bits, only 64 bits provided
- Laravel's whereBetween method not working with two timestamps
- Implementing UUID as primary key in Laravel intermediate table
Related Questions in CHARACTER-ENCODING
- Can't we make a better variable-length character encoding with just using the 1 bit extra in the 7 bit ASCII?
- Cpanel filter encoding utf-8?
- bagaimana cara menginstall steghide lewat mac
- Encoding problem on MySQL: Why some non-ASCII characters get encoded on more than 4 bytes?
- Matching multi-language (latin extended) characters in lua
- Handle mixed charsets in the same json file
- MIPS Aiken to Binary
- I am not sure why I need to Encode path parameter TWICE to make the rest call with special chars to work?
- having character encoding problem on my blog content in php application
- Visual C++ - how can I turn a unicode character into char or string?
- Cypresss Unable to Load UTF-16 Website on Brower Launch
- How to set encoding?
- HL7 encoding characters in non-ASCII strings
- How to fix these two warnings about implicit string cast during charset conversion?
- Python PyODBC and SQL Server encoding issue
Related Questions in PHP-STREAM-WRAPPERS
- PHP: create gz stream from plain file
- PHP - stream crypto enabled server cuts off bytes
- How To Read A File in php wrappers as utf-16
- Is it possible to use glob pattern for matching zip contents?
- how to put stream php://temp content to html
- how to replace a string in a stream for very large files
- How to pass options to stream_open in google cloud PHP stream wrapper
- How to read content from 'php://output' stream
- Encrypting native PHP streams
- Difference between using "file://" stream wrapper or put directly file path (PHP)
- curl works, sockets fail for most domains and IPs
- File copied from a URL is truncated
- PHP; get post string from external url (JAVA)
- How can I implement a PHP stream wrapper to modify the output of another wrapper?
- How to set the default chunk size for a custom PHP stream wrapper
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
PHP strings don't know anything about encodings, so PHP file functions essentially treat every file as a binary file.
If you know that a set of bytes should be read as UTF-16, you can convert it to some other encoding of your choice (here using UTF-8 as an example) using any of these (depending which extensions you have installed):
Conversely, if you know that the string is in some particular encoding (again, using UTF-8 as an example), and want it to be UTF-16, you would put things in the opposite order:
In both cases, the resulting string is just a different sequence of bytes; other PHP functions still won't "know" what it "means".
The "iconv" extension also provides a conversion filter which runs the equivalent of the
iconvfunction as a file or stream is being read. So if you have a file which you know should be read as UTF-16, and want its contents as UTF-8, you could write:Or the reverse - a UTF-8 file which you want to read as UTF-16:
Again, it's important to remember that PHP is working in bytes, so the
fgetscalls above may result in corrupted text because the 10th byte wasn't the end of a Unicode code point.