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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:49:44+00:00 2026-06-08T15:49:44+00:00

I encountered a particular string (it’s not completely printable, but you can see it

  • 0

I encountered a particular string (it’s not completely printable, but you can see it below) that causes a htmlspecialchars() to return a zero-length string. Is there any way this can be fixed?

$Stmnt = 'SELECT subject_name FROM bans WHERE id = 2321';
$Fetch = $Conn->query($Stmnt);
if(!$Fetch)
    die('Could not query DB');
while($Row = $Fetch->fetch_array(MYSQLI_ASSOC))
{
    $RawName = $Row['subject_name'];
    $RawLen = strlen($RawName);
    echo('RAW NAME: ['.$RawName.']'.', LENGTH: ['.$RawLen.']'.'<br />');
    for($i = 0; $i < $RawLen; $i++)
        echo('CHAR '.$i.' = ['.$RawName[$i].'] (ORD: '.ord($RawName[$i]).')<br />');

    $CleanName = htmlspecialchars($RawName, ENT_QUOTES, 'UTF-8');
    $CleanLen = strlen($CleanName);
    echo('CLEAN NAME: ['.$CleanName.']'.', LENGTH: ['.$CleanLen.']'.'<br />');
    for($i = 0; $i < $CleanLen; $i++)
        echo('CHAR '.$i.' = ['.$CleanName[$i].'] (ORD: '.ord($CleanName[$i]).')<br />');
}
$Fetch->close();
echo('DONE');

Output:

RAW NAME: [━═★ Coммander Fι5н �], LENGTH: [31]
CHAR 0 = [�] (ORD: 226)
CHAR 1 = [�] (ORD: 148)
CHAR 2 = [�] (ORD: 129)
CHAR 3 = [�] (ORD: 226)
CHAR 4 = [�] (ORD: 149)
CHAR 5 = [�] (ORD: 144)
CHAR 6 = [�] (ORD: 226)
CHAR 7 = [�] (ORD: 152)
CHAR 8 = [�] (ORD: 133)
CHAR 9 = [ ] (ORD: 32)
CHAR 10 = [C] (ORD: 67)
CHAR 11 = [o] (ORD: 111)
CHAR 12 = [�] (ORD: 208)
CHAR 13 = [�] (ORD: 188)
CHAR 14 = [�] (ORD: 208)
CHAR 15 = [�] (ORD: 188)
CHAR 16 = [a] (ORD: 97)
CHAR 17 = [n] (ORD: 110)
CHAR 18 = [d] (ORD: 100)
CHAR 19 = [e] (ORD: 101)
CHAR 20 = [r] (ORD: 114)
CHAR 21 = [ ] (ORD: 32)
CHAR 22 = [F] (ORD: 70)
CHAR 23 = [�] (ORD: 206)
CHAR 24 = [�] (ORD: 185)
CHAR 25 = [5] (ORD: 53)
CHAR 26 = [�] (ORD: 208)
CHAR 27 = [�] (ORD: 189)
CHAR 28 = [ ] (ORD: 32)
CHAR 29 = [�] (ORD: 226)
CHAR 30 = [�] (ORD: 148)
CLEAN NAME: [], LENGTH: [0]
DONE
  • 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-08T15:49:51+00:00Added an answer on June 8, 2026 at 3:49 pm

    I understand now why it’s returning a zero-length string. Sorry for asking this question. I should have researched more before posting. Anyway, the answer is the following:

    On the PHP manual page for htmlspecialchars:

    If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

    Then I ask myself what is “invalid” about this string? On the Wiki page for UTF-8 it gives a good diagram of UTF-8 encoding. All codepoints representing “plain text ASCII” would be 0-127 (the MSB in the byte is always 0).

    If a byte’s MSB is 1 (decimal 128 to 255) it tells a UTF-8 compliant parser that the codepoint consists of a multi-byte chain. And the next byte’s first two Most-Significant-Bits must be a 1 followed by a 0.

    Obviously in this string, there is a case where one byte is over 127 and the following byte does not begin with a 1 & 0. Therefore it is invalid UTF-8 encoding.

    Thanks for this SO post for the resolution, which in my opinion, is to use the ENT_SUBSTITUTE flag (or I suppose ENT_IGNORE if you are sure that deleting these non-conforming bytes won’t be a security issue).

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

Sidebar

Related Questions

I have used COALESCE numerous times but I suppose I never encountered this particular
i encountered a problem using the apache commons-net telnet api, and hope you can
I encountered this error: The type or namespace name 'WebControls' could not be found
I'm sure that this question has been addressed in many best practices books, but
Here is an interesting problem that I encountered in a programming competition: Problem statement:
I have written a program in .NET that listens to a particular Serial Port
I just encountered a problem with @unittest.skipIf(expression) . Well, the problem is that if
I am writing a code analysis tool that uses reflection to validate a particular
I wrote C++ for 10 years. I encountered memory problems, but they could be
Today I encountered an interesting problem. When I navigate to a particular website and

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.