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

  • Home
  • SEARCH
  • 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 1090349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:21:40+00:00 2026-05-16T23:21:40+00:00

Given a Unicode decimal or hex number for a character that’s wanting to be

  • 0

Given a Unicode decimal or hex number for a character that’s wanting to be output from a CLI PHP script, how can PHP generate it? The chr() function seems to not generate the proper output. Here’s my test script, using the Section Break character U+00A7 (A7 in hex, 167 in decimal, should be represented as C2 A7 in UTF-8) as a test:

<?php
echo "Section sign: ".chr(167)."\n"; // Using CHR function
echo "Section sign: ".chr(0xA7)."\n";
echo "Section sign: ".pack("c", 0xA7)."\n"; // Using pack function?
echo "Section sign: §\n"; // Copy and paste of the symbol into source code

The output I get (via a SSH session to the server) is:

Section sign: ?
Section sign: ?
Section sign: ?
Section sign: §

So, that proves that the terminal font I’m using has the Section Break character in it, and the SSH connection is sending it along successfully, but chr() isn’t constructing it properly when constructing it from the code number.

If all I’ve got is the code number and not a copy/paste option, what options do I have?

  • 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-16T23:21:41+00:00Added an answer on May 16, 2026 at 11:21 pm

    PHP has no knowledge of Unicode when excluding the mb_ functions and iconv. You’ll have to UTF-8 encode the character yourself.

    For that, Wikipedia has an excellent overview on how UTF-8 is structured. Here’s a quick, dirty and untested function based on that article:

    function codepointToUtf8($codepoint)
    {
        if ($codepoint < 0x7F) // U+0000-U+007F - 1 byte
            return chr($codepoint);
        if ($codepoint < 0x7FF) // U+0080-U+07FF - 2 bytes
            return chr(0xC0 | ($codepoint >> 6)).chr(0x80 | ($codepoint & 0x3F);
        if ($codepoint < 0xFFFF) // U+0800-U+FFFF - 3 bytes
            return chr(0xE0 | ($codepoint >> 12)).chr(0x80 | (($codepoint >> 6) & 0x3F).chr(0x80 | ($codepoint & 0x3F);
        else // U+010000-U+10FFFF - 4 bytes
            return chr(0xF0 | ($codepoint >> 18)).chr(0x80 | ($codepoint >> 12) & 0x3F).chr(0x80 | (($codepoint >> 6) & 0x3F).chr(0x80 | ($codepoint & 0x3F);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I replace non-ascii chars from a unicode string in Python? This are
I am given either a single character or a string, and am using Python.
ueach is a function that loops through a Unicode string, and running the callback
there is more elegant (pythonic + effective) way to find word on given position?
I was wondering how to calculate the hash code for a given string by
I have the following code (VB.NET) which is designed to determine if a given
I want to import emails from an mbox format into a Django app. All
When I execute the following cucumber script: Feature: Manage Customers In order to store
**models.py** class Category(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Gender(models.Model): name =

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.