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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:04:57+00:00 2026-05-20T01:04:57+00:00

How can I encode the value of a filename according to the encoding of

  • 0

How can I encode the value of a filename according to the encoding of MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations (RFC 2231)?

  • 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-20T01:04:58+00:00Added an answer on May 20, 2026 at 1:04 am

    I think this should do it:

    function rfc2231_encode($name, $value, $charset='', $lang='', $ll=78) {
        if (strlen($name) === 0 || preg_match('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', $name)) {
            // invalid parameter name;
            return false;
        }
        if (strlen($charset) !== 0 && !preg_match('/^[A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*$/', $charset)) {
            // invalid charset;
            return false;
        }
        if (strlen($lang) !== 0 && !preg_match('/^[A-Za-z]{1,8}(?:-[A-Za-z]{1,8})*$/', $lang)) {
            // invalid language;
            return false;
        }
        $value = "$charset'$lang'".preg_replace_callback('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', function($match) { return rawurlencode($match[0]); }, $value);
        $nlen = strlen($name);
        $vlen = strlen($value);
        if (strlen($name) + $vlen > $ll-3) {
            $sections = array();
            $section = 0;
            for ($i=0, $j=0; $i<$vlen; $i+=$j) {
                $j = $ll - $nlen - strlen($section) - 4;
                $sections[$section++] = substr($value, $i, $j);
            }
            for ($i=0, $n=$section; $i<$n; $i++) {
                $sections[$i] = " $name*$i*=".$sections[$i];
            }
            return implode(";\r\n", $sections);
        } else {
            return " $name*=$value";
        }
    }
    

    Note that this function expects that the output is used in a separate line preceded by a proper line wrap (i.e. CRLF), e.g.:

    "Content-Type: application/x-stuff;\r\n".rfc2231_encode('title', 'This is even more ***fun*** isn\'t it!', 'us-ascii', 'en', 48)
    

    The output is:

    Content-Type: application/x-stuff;
     title*0*=us-ascii'en'This%20is%20even%20more%20;
     title*1=%2A%2A%2Afun%2A%2A%2A%20isn%27t%20it!
    

    See also Test Cases for HTTP Content-Disposition header field and the Encodings defined in RFC 2047 and RFC 2231/5987.

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

Sidebar

Related Questions

How can I encode the Unicode character U+0048 (H), say, in a PowerShell string?
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 38: ordinal not in range(128)
I have a PHP script that can encode a PNG image to a Base64
I know the class SimpleXMLEncoder can encode all properties of an Object in XML.
I need an OpenSource API in Java, which can encode *.wav and *.au formats
For example, if I have a unicode string, I can encode it as an
How can I encode a file using sha256 and c/c++ ??? Thanks!
I'm looking for a method in which I can decode and encode text to
How can I use Speex to encode/decode from within python? Are there any wrappers?
Every method I write to encode a string in Java using 3DES can't be

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.