chr

(PHP 4, PHP 5)

chrВозвращает символ по его коду

Описание

string chr ( int $ascii )

Возвращает строку из одного символа, код которого задан аргументом ascii.

Эта функция дополняет функцию ord().

Список параметров

ascii

ASCII-код.

Возвращаемые значения

Возвращает символ по его коду.

Примеры

Пример #1 Пример использования chr()

<?php
$str 
"Эта строка заканчивается на escape: ";
$str .= chr(27); /* добавляет символ escape в конец $str */

/* Но обычно лучше использовать такую конструкцию */

$str sprintf("The string ends in escape: %c"27);
?>

Смотрите также

Коментарии

[Editor's note:

%c is defined as: "Print the character belonging to the ascii code given"

chr() just gives a string, so you need to use %s, even if the string consists of only one character. This is consistent with other languages.
--Jeroen@php.net]


Learn from my mistake:
Do not expect this to work!

<?php
$c_question 
chr(63);
$v_out sprintf("<%cphp\n"$c_question);
//... more stuff being sprintf'd into v_out here ...
$v_out sprintf("%s%c>\n"$v_out$c_question);
$v_fp fopen("foofile""w");
if (
$v_fp)
{
     
fwrite($v_fp$v_outstrlen($v_out));
     
fclose($v_fp);
}
?>

When I did this, foofile contained <NUL NUL NUL NUL NUL>.
I spun my wheels quite awhile looking at fputs, fwrite to verify I was calling those functions correctly.
My mistake was using $c_question = chr(63) instead of
$c_question = 63 (correct).  Then everything worked fine.
2000-05-09 19:59:24
http://php5.kiev.ua/manual/ru/function.chr.html
Here is a function that's help me find what chr(number) outputs what character quicker than typing out 256 echo tags.

<?php
 
function listChr(){
  for (
$i 0$i 256; ++$i) {
  static 
$genNum;
 
$genNum++;
  echo 
"chr($genNum) will output '";
  echo (
chr($genNum));
  echo 
"'< br>\n";
  }
}
listChr();
?>

Another helpful chr is #9, being a tab.  Quite using when making error logs.

 $tab = (chr(9));
 echo "<pre>error{$tab}date{$tab}time</pre>";

 -- HappyEvil
2001-03-26 22:31:01
http://php5.kiev.ua/manual/ru/function.chr.html
\n == &#13;
Usefull if u want to display multi-line-alt-strings
e.g. <img src="/gifs/php_logo.gif" alt="Here u can see the&#13;PHPLogo&#13;3rd line">
2002-04-13 15:51:42
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
This bit of code will convert all those lovely tilde,umlaut etc. etc. characters into safe character codes:

<?php
    $trans_array 
= array();
    for (
$i=127$i<255$i++) {
       
$trans_array[chr($i)] = "&#" $i ";";
    }
   
$outtext strtr($intext$trans_array);
?>
2002-06-28 23:05:45
http://php5.kiev.ua/manual/ru/function.chr.html
Here's a small function I wrote up to generate random passwords using the chr() function.

<?php
function randPass($len)
{
 
$pw ''//intialize to be blank
 
for($i=0;$i<$len;$i++)
 {
   switch(
rand(1,3))
   {
     case 
1$pw.=chr(rand(48,57));  break; //0-9
     
case 2$pw.=chr(rand(65,90));  break; //A-Z
     
case 3$pw.=chr(rand(97,122)); break; //a-z
   
}
 }
 return 
$pw;
}
?>

Example:

<?php
 $password 
randPass(10); //assigns 10-character password
?>

I found this useful in my early coding days... I'm sure someone else will too :D
2002-11-08 18:17:29
http://php5.kiev.ua/manual/ru/function.chr.html
Want terminal colors in command line php scripts?

This should take care of that.
<?

$_colors 
= array(
       
'LIGHT_RED'      => "[1;31m",
       
'LIGHT_GREEN'     => "[1;32m",
       
'YELLOW'     => "[1;33m",
       
'LIGHT_BLUE'     => "[1;34m",
       
'MAGENTA'     => "[1;35m",
       
'LIGHT_CYAN'     => "[1;36m",
       
'WHITE'     => "[1;37m",
       
'NORMAL'     => "[0m",
       
'BLACK'     => "[0;30m",
       
'RED'         => "[0;31m",
       
'GREEN'     => "[0;32m",
       
'BROWN'     => "[0;33m",
       
'BLUE'         => "[0;34m",
       
'CYAN'         => "[0;36m",
       
'BOLD'         => "[1m",
       
'UNDERSCORE'     => "[4m",
       
'REVERSE'     => "[7m",

);

function 
termcolored($text$color="NORMAL"$back=1){
    global 
$_colors;
   
$out $_colors["$color"];
    if(
$out == ""){ $out "[0m"; }
    if(
$back){
        return 
chr(27)."$out$text".chr(27).chr(27)."[0m".chr(27);
    }else{
        echo 
chr(27)."$out$text".chr(27).chr(27)."[0m".chr(27);
    }
//fi
}// end function

echo termcolored("test\n""BLUE");
?>
2002-12-14 16:53:42
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
Note that chr(10) is a 'line feed' and chr(13) is a 'carriage return' and they are not the same thing! I found this out while attempting to parse text from forms and text files for inclusion as HTML by replacing all the carriage returns with <BR>'s only to find after many head-scratchings that I should have been looking for line feeds. If anyone can shed some light on what the difference is, please do.

If you're planning on saving text from a form into a database for later display, you'll need to apply the following function so that it gets saved with the proper HTML tags.

<?php
$text 
str_replace chr(10), "<BR>"$text );
?>

When you want to plug it back into that form for editing you need to convert it back.

<?php
$text 
str_replace "<BR>"chr(10), $text)
?>

Hope this saves somebody some trouble. :)
2003-03-06 22:19:11
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
A quick function that I use to make strings "XML" compliant, changing every special character into their #$... equivalent.

htmlentities doesn't get all of the chars above 127, so the second part of this (which I stole from one of the comments above) finishes the process, returning a nice, xml happy string.

<?php
   
function strictify $string ) {

       
$fixed htmlentities$stringENT_QUOTES );

       
$trans_array = array();
        for (
$i=127$i<255$i++) {
           
$trans_array[chr($i)] = "&#" $i ";";
        }

       
$really_fixed strtr($fixed$trans_array);

        return 
$really_fixed;

    }
?>

HTH
2003-03-26 20:12:34
http://php5.kiev.ua/manual/ru/function.chr.html
Cutting Korean(2Byte)-String

<?php
function cutStr($str,$len){
    if(
strlen($str) > $len){
       
$str substr($str,0,$len 2);
        if(
strlen(substr(strrchr($str," "),1)) % 2)
           
$str substr($str,0,strlen($str) - 1);
       
$str .= "..";
    }
    return 
$str;
}
?>
2003-06-24 23:16:41
http://php5.kiev.ua/manual/ru/function.chr.html
Lowercase alphabet:
<?php for($a=97;$a<(97+26);$a++){ echo chr($a); } ?>
2003-07-25 13:20:58
http://php5.kiev.ua/manual/ru/function.chr.html
Note that if the number is higher than 256, it will return the number mod 256.
For example :
chr(321)=A because A=65(256)
2004-04-11 19:20:27
http://php5.kiev.ua/manual/ru/function.chr.html
Here is a function that will convert column numbers in to a letters for use in a spreadsheet.  It is limited up to 'ZZ' but can easliy by modifed.

<?php
 
function col2chr($a){
        if(
$a<27){
            return 
strtoupper(chr($a+96));   
        }else{
            while(
$a 26){
               
$b++;
               
$a $a-26;               
            }                   
           
$b strtoupper(chr($b+96));   
           
$a strtoupper(chr($a+96));               
            return 
$b.$a;
        }
    }
?>
2004-04-13 17:42:22
http://php5.kiev.ua/manual/ru/function.chr.html
When having to deal with parsing an IIS4 or IIS5 metabase dump I wrote a simple function for converting those MS hexidecimal values into their ascii counter parts. Hopefully someone will find use for it.

<?php
function hex_decode($string)  {
        for (
$i=0$i strlen($string); $i)  {
       
$decoded .= chr(hexdec(substr($string,$i,2)));
       
$i = (float)($i)+2;
        }
return 
$decoded;
}
?>
2004-07-15 02:05:07
http://php5.kiev.ua/manual/ru/function.chr.html
The following function helped me to generate ascii-only usernames from firstname/lastname containing iso-8859-2 characters. The convertion array was based on contents of 'man iso-8859-2'.

Example: iso2ascii("b&#322;a&#380;ej.&#378;d&#378;b&#322;o") returns "blazej.zdzblo"

<?php
function iso2ascii($str) {
 
$arr=array(
 
chr(161)=>'A'chr(163)=>'L'chr(165)=>'L'chr(166)=>'S'chr(169)=>'S',
 
chr(170)=>'S'chr(171)=>'T'chr(172)=>'Z'chr(174)=>'Z'chr(175)=>'Z',
 
chr(177)=>'a'chr(179)=>'l'chr(181)=>'l'chr(182)=>'s'chr(185)=>'s',
 
chr(186)=>'s'chr(187)=>'t'chr(188)=>'z'chr(190)=>'z'chr(191)=>'z',
 
chr(192)=>'R'chr(193)=>'A'chr(194)=>'A'chr(195)=>'A'chr(196)=>'A',
 
chr(197)=>'L'chr(198)=>'C'chr(199)=>'C'chr(200)=>'C'chr(201)=>'E',
 
chr(202)=>'E'chr(203)=>'E'chr(204)=>'E'chr(205)=>'I'chr(206)=>'I',
 
chr(207)=>'D'chr(208)=>'D'chr(209)=>'N'chr(210)=>'N'chr(211)=>'O',
 
chr(212)=>'O'chr(213)=>'O'chr(214)=>'O'chr(216)=>'R'chr(217)=>'U',
 
chr(218)=>'U'chr(219)=>'U'chr(220)=>'U'chr(221)=>'Y'chr(222)=>'T',
 
chr(223)=>'s'chr(224)=>'r'chr(225)=>'a'chr(226)=>'a'chr(227)=>'a',
 
chr(228)=>'a'chr(229)=>'l'chr(230)=>'c'chr(231)=>'c'chr(232)=>'c',
 
chr(233)=>'e'chr(234)=>'e'chr(235)=>'e'chr(236)=>'e'chr(237)=>'i',
 
chr(238)=>'i'chr(239)=>'d'chr(240)=>'d'chr(241)=>'n'chr(242)=>'n',
 
chr(243)=>'o'chr(244)=>'o'chr(245)=>'o'chr(246)=>'o'chr(248)=>'r',
 
chr(249)=>'u'chr(250)=>'u'chr(251)=>'u'chr(252)=>'u'chr(253)=>'y',
 
chr(254)=>'t'
 
);
 return 
strtr($str,$arr);
}
?>
2005-02-17 06:26:32
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
If you want to increment your letter, which is stored as a string, you have to convert it back to an integer first.

<?php
    $letter
=strtolower($_GET['letter']);    //You wanted this originally, but not decided you want the previous letter
   
$letter=ord($letter);            //Convert to an integer
   
$letter=chr($letter-1);            //Convert back to a string, but the previous letter (naturally won't work with A or a)
?>
2005-05-24 10:15:29
http://php5.kiev.ua/manual/ru/function.chr.html
I spent hours looking for a function which would take a numeric HTML entity value and output the appropriate UTF-8 bytes.  I found this at another site and only had to modify it slightly; so I don't take credit for this.

<?php function unichr($dec) { 
  if (
$dec 128) { 
   
$utf chr($dec); 
  } else if (
$dec 2048) { 
   
$utf chr(192 + (($dec - ($dec 64)) / 64)); 
   
$utf .= chr(128 + ($dec 64)); 
  } else { 
   
$utf chr(224 + (($dec - ($dec 4096)) / 4096)); 
   
$utf .= chr(128 + ((($dec 4096) - ($dec 64)) / 64)); 
   
$utf .= chr(128 + ($dec 64)); 
  } 
  return 
$utf;
?>

So for example:

<?php

  $str 
"Chinese: &#20013;&#25991;";
 
$str preg_replace("/&#(\d{2,5});/e""unichr($1);"$str);

?>
2005-08-19 10:55:32
http://php5.kiev.ua/manual/ru/function.chr.html
I made a password generator with this function...

<?php
$passlength 
8;
$pass "";
$i 0;
while(
$i <= $passlength)
    {
   
$pass .= chr(rand(33,126));
   
$i++;
    }
echo 
$pass;
?>

Ofcourse you can change passlength.

Example of an 8-char password:
AFJ\)t'u}

I realise it isn't compatible for all sites, but most will accept :)
2006-01-08 12:51:06
http://php5.kiev.ua/manual/ru/function.chr.html
bear in mind that php doesn't really care about character sets. php strings are just arbitary byte sequences thier meaning (especailly when you go beyond code 127) depends entirely on whats interpreting the data (in the case of a browser the charset specified in the http headers).
2006-01-14 14:41:48
http://php5.kiev.ua/manual/ru/function.chr.html
I found this function useful as a way to detect and to replace Microsoft Smart Quotes when desplaying info on a webpage.

The following lines seem to do the trick:

<?php
$text 
"string containing Microsoft Smart Quotes...";
$chrs = array (chr(150), chr(147), chr(148), chr(146));
$repl = array ("-""\"""\"""'");
$text str_replace($chrs$repl$text);
?>
2006-02-13 16:52:02
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
I didn't see it here, so here's simple random string generation using char.

<?php
for($i=0$i<7$i++){
   
$random_string .= chr(rand(0,25)+65);
}
echo 
$random_string;
?>
2006-02-16 21:34:05
http://php5.kiev.ua/manual/ru/function.chr.html
Unicode version of chr() using mbstring
<?php
 
function unichr($u) {
    return 
mb_convert_encoding(pack("N",$u), mb_internal_encoding(), 'UCS-4BE');
  }
?>
It returns a string in internal encoding (possibly more than one byte).
2006-08-22 11:20:04
http://php5.kiev.ua/manual/ru/function.chr.html
chr() with unicode support

<?php

function uchr ($codes) {
    if (
is_scalar($codes)) $codesfunc_get_args();
   
$str'';
    foreach (
$codes as $code$str.= html_entity_decode('&#'.$code.';',ENT_NOQUOTES,'UTF-8');
    return 
$str;
}

echo 
uchr(23383); echo '<br/>';
echo 
uchr(23383,215,23383); echo '<br/>';
echo 
uchr(array(23383,215,23383,215,23383)); echo '<br/>';

?>
2007-04-27 07:33:47
http://php5.kiev.ua/manual/ru/function.chr.html
First, the linefeed versus carriage return confusion:

When typewriters were first invented they were manually moved.  You could do a couple of things with them.  You could type on it (which would move the carriage one space to the left as you typed each character), you could hit the backspace key (which would move the carriage one space to the right), press the line feed button (which would cause the carriage to roll up one line), and return (which would move the carriage all the way to the right again).  When electric typewriters came in to being these functions were made into their electronic counterparts. When terminals appeared they were given the same functions just as word processors, text editors, and everything else that deals with the typed word handles them.

When computers first came out though, the dopey people who invented them wanted to distinguish themselves.  One of the ways they did that was to only use some of the commands.  Which is why the Macintosh originally only used the carriage return command and why Linux/Unix only used the line feed command.  This is why there is "\r" (carriage return), "\l" (Line Feed), and "\n" (OS appropriate).  One of the few things that IBM got right was that it should really be <Carriage Return><Line Feed> and not just one or the other.

So like the reason our roads are a certain width is because that was the width of two horses pulling a Roman chariot, the reason we use these terms is because of the humble non-electronic typewriter and how it worked.

Second - I believe that PHP actually generates ANSI characters and not ASCII characters.  Although there were different extended character sets for the ASCII characters (ie: 128-255), the one depicted on the http://www.asciitable.com/ website clearly shows the IBM standardized ASCII extended table.  (ie: If you ran a BASIC program on your computer you would see the set shown on the above website.)  If, however, you print out the characters via the CHR() function in PHP it prints out the ANSI character set.  (ASCII and ANSI are the same for 0-127.)  Although you can get the characters to print (via Unicode) through the CHR() function - this is still simply showing it is using ANSI and not ASCII.  (Because Unicode is an extension of the ANSI character set and not the ASCII character set.)

If this is so (and my tests show it is) - should the documentation be changed to reflect this?  :-?
2008-07-09 18:34:54
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
In addition to replacing Microsoft Windows smart quotes, as sgaston demonstrated on 2006-02-13, I replace all other Microsoft Windows characters using suggestions[1] published by character code specialist[2] Jukka Korpela.

<?php
$str 
str_replace(chr(130), ','$str);    // baseline single quote
$str str_replace(chr(131), 'NLG'$str);  // florin
$str str_replace(chr(132), '"'$str);    // baseline double quote
$str str_replace(chr(133), '...'$str);  // ellipsis
$str str_replace(chr(134), '**'$str);   // dagger (a second footnote)
$str str_replace(chr(135), '***'$str);  // double dagger (a third footnote)
$str str_replace(chr(136), '^'$str);    // circumflex accent
$str str_replace(chr(137), 'o/oo'$str); // permile
$str str_replace(chr(138), 'Sh'$str);   // S Hacek
$str str_replace(chr(139), '<'$str);    // left single guillemet
$str str_replace(chr(140), 'OE'$str);   // OE ligature
$str str_replace(chr(145), "'"$str);    // left single quote
$str str_replace(chr(146), "'"$str);    // right single quote
$str str_replace(chr(147), '"'$str);    // left double quote
$str str_replace(chr(148), '"'$str);    // right double quote
$str str_replace(chr(149), '-'$str);    // bullet
$str str_replace(chr(150), '-'$str);    // endash
$str str_replace(chr(151), '--'$str);   // emdash
$str str_replace(chr(152), '~'$str);    // tilde accent
$str str_replace(chr(153), '(TM)'$str); // trademark ligature
$str str_replace(chr(154), 'sh'$str);   // s Hacek
$str str_replace(chr(155), '>'$str);    // right single guillemet
$str str_replace(chr(156), 'oe'$str);   // oe ligature
$str str_replace(chr(159), 'Y'$str);    // Y Dieresis
?>

[1] On the use of some MS Windows characters in HTML
http://www.cs.tut.fi/~jkorpela/www/windows-chars.html

[2] Unicode Explained by Jukka Korpela 
http://www.amazon.com/dp/059610121X/
2008-08-12 17:06:47
http://php5.kiev.ua/manual/ru/function.chr.html
Secure password generator with a variable maximum amount of symbols.

<?php

function passwdGen($minLength 8$maxLength 12$maxSymbols 2)
{
   
$symbolCount 0;

   
srand((double)microtime() * 1000003);

    for (
$i 0$i rand($minLength$maxLength); $i++)
    {
        do
        {
           
$char rand(33126);

           
$symbolCount += $isSymbol = (!in_array($charrange(4857)) && !in_array($charrange(6590)) && !in_array($charrange(97122)));

            if (
$symbolCount <= $maxSymbols || !$isSymbol)
            {
                break;
            }
        }
        while (
true);

       
$passwd sprintf('%s%c', isset($passwd) ? $passwd NULL$char);
    }

    return 
$passwd;
}

?>
2008-10-21 00:51:57
http://php5.kiev.ua/manual/ru/function.chr.html
This function creates a ascii table, and replaces all the ascii characters in the mail.
---
Deze functie maakt een ascii tabel, en zet alles juist om.

<?php
 
function makeASCII($a){
 
$find[] = "=\r\n";
 
$replace[] = "";
 
  for(
$i=0$i 256$i++){
   
$find[] = "=".dechex($i)."";
   
$replace[] = chr($i);
  }
 
$a str_replace($find,$replace,$a);
  return 
$a;
 }
?>
2008-12-31 07:46:02
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
Another quick and short function to get unicode char by its code.

<?php
/**
 * Return unicode char by its code
 *
 * @param int $u
 * @return char
 */
function unichr($u) {
    return 
mb_convert_encoding('&#' intval($u) . ';''UTF-8''HTML-ENTITIES');
}
?>
2009-01-31 09:39:13
http://php5.kiev.ua/manual/ru/function.chr.html
Thank you joeldegan for your termcolored function.  I write a lot of command-line scripts using PHP and like to colorize them.  I was having a problem with the termcolored function where the next character echo'ed after calling termcolored() was being dropped.  Turns out you don't need the extra chr(27) at the end of each term color code.

Here's my modified version of your function, renamed to echocolor.

<?php
function echocolor($text,$color="normal",$back=0)
{
 
$colors = array('light_red'  => "[1;31m"'light_green' => "[1;32m"'yellow'     => "[1;33m",
                 
'light_blue' => "[1;34m"'magenta'     => "[1;35m"'light_cyan' => "[1;36m",
                 
'white'      => "[1;37m"'normal'      => "[0m",    'black'      => "[0;30m",
                 
'red'        => "[0;31m"'green'       => "[0;32m"'brown'      => "[0;33m",
                 
'blue'       => "[0;34m"'cyan'        => "[0;36m"'bold'       => "[1m",
                 
'underscore' => "[4m",    'reverse'     => "[7m" );
 
$out $colors["$color"];
 
$ech chr(27)."$out"."$text".chr(27)."[0m";
  if(
$back)
  {
    return 
$ech;
  }
  else
  {
    echo 
$ech;
  }
}
?>
2009-03-10 13:27:28
http://php5.kiev.ua/manual/ru/function.chr.html
The function chr() also accepts negative numbers as an ascii code, so chr(-number) is equal to chr((number%256)+256).
And for ascii code higher than 255 is chr(number%256)

We can test with a little script
<?php
   
for($i=-300$i<300$i++){
        echo 
"Ascii $i\t" ord(chr($i)) . "\n";
    }
?>
2009-06-30 05:38:26
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
Replaces special characters with non-special equivalents

<?php
function normalize_special_characters$str )
{
   
# Quotes cleanup
   
$str ereg_replacechr(ord("`")), "'"$str );        # `
   
$str ereg_replacechr(ord("´")), "'"$str );        # ´
   
$str ereg_replacechr(ord("„")), ","$str );        # „
   
$str ereg_replacechr(ord("`")), "'"$str );        # `
   
$str ereg_replacechr(ord("´")), "'"$str );        # ´
   
$str ereg_replacechr(ord("“")), "\""$str );        # “
   
$str ereg_replacechr(ord("”")), "\""$str );        # ”
   
$str ereg_replacechr(ord("´")), "'"$str );        # ´

   
$unwanted_array = array(    'Š'=>'S''š'=>'s''Ž'=>'Z''ž'=>'z''À'=>'A''Á'=>'A''Â'=>'A''Ã'=>'A''Ä'=>'A''Å'=>'A''Æ'=>'A''Ç'=>'C''È'=>'E''É'=>'E',
                               
'Ê'=>'E''Ë'=>'E''Ì'=>'I''Í'=>'I''Î'=>'I''Ï'=>'I''Ñ'=>'N''Ò'=>'O''Ó'=>'O''Ô'=>'O''Õ'=>'O''Ö'=>'O''Ø'=>'O''Ù'=>'U',
                               
'Ú'=>'U''Û'=>'U''Ü'=>'U''Ý'=>'Y''Þ'=>'B''ß'=>'Ss''à'=>'a''á'=>'a''â'=>'a''ã'=>'a''ä'=>'a''å'=>'a''æ'=>'a''ç'=>'c',
                               
'è'=>'e''é'=>'e''ê'=>'e''ë'=>'e''ì'=>'i''í'=>'i''î'=>'i''ï'=>'i''ð'=>'o''ñ'=>'n''ò'=>'o''ó'=>'o''ô'=>'o''õ'=>'o',
                               
'ö'=>'o''ø'=>'o''ù'=>'u''ú'=>'u''û'=>'u''ý'=>'y''ý'=>'y''þ'=>'b''ÿ'=>'y' );
   
$str strtr$str$unwanted_array );

   
# Bullets, dashes, and trademarks
   
$str ereg_replacechr(149), "&#8226;"$str );    # bullet •
   
$str ereg_replacechr(150), "&ndash;"$str );    # en dash
   
$str ereg_replacechr(151), "&mdash;"$str );    # em dash
   
$str ereg_replacechr(153), "&#8482;"$str );    # trademark
   
$str ereg_replacechr(169), "&copy;"$str );    # copyright mark
   
$str ereg_replacechr(174), "&reg;"$str );        # registration mark

   
return $str;
}
?>
2009-09-01 10:36:11
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
Here is code for generation Russian alphabet:
<?php
for ($i=176;$i<=207;++$i) {
    echo 
$i.'='.iconv('ISO-8859-5''UTF-8'chr($i)).'<br>';
}
?>
This simple code generates all Russian capital letters, but without 'Ё'.
2010-03-11 10:31:12
http://php5.kiev.ua/manual/ru/function.chr.html
Here is a sample of encoding and decoding using "chr" and "ord".
<?php
   
function Encode($txtData,$Level){
        for (
$j 0;$j<$Level;$j++){
           
$tmpStr '';
            for (
$i 0;$i<strlen($txtData);$i++)
               
$tmpStr .= ord(substr(strtoupper($txtData), $i1));
           
$txtData $tmpStr;
        }
        return (
strlen($Level)).$Level.$txtData;
    }

    function 
Decode($txtData){
       
$intLevel substr($txtData1substr($txtData01));
       
$startStr substr($txtDatasubstr($txtData01)+1strlen($txtData));
        for (
$j 0;$j<$intLevel;$j++){
            for (
$i 0;$i<strlen($startStr);$i+=2)
               
$tmpStr .= chr(intval(substr($startStr$i2)));
           
$startStr $tmpStr;
       
           
$tmpStr "";
        }
        return 
$startStr;
    }

echo 
Encode('123',4).'<br>';
echo 
Decode(Encode('123',5));
?>
2011-02-04 10:17:35
http://php5.kiev.ua/manual/ru/function.chr.html
Автор:
While the documentation appears to imply ASCII character operation only, chr() can actually be used to convert arbitrary byte values into binary content:

<?php

while( @$i++ < 32 )
   
$a chrmt_rand(0255) );

file_put_contents'filename'$a );

?>
2011-09-24 11:46:14
http://php5.kiev.ua/manual/ru/function.chr.html
There is simple function for converting number to chars. If you want make table like excel where colums are indetified by chars A,B,C...AA,AB.. you can easyli iterate on integer and call this function.
<?php
function numtochars($num,$start=65,$end=90)
{
   
$sig = ($num 0);
   
$num abs($num);
   
$str "";
   
$cache = ($end-$start);
    while(
$num != 0)
    {
       
$str chr(($num%$cache)+$start-1).$str;
       
$num = ($num-($num%$cache))/$cache;
    }
    if(
$sig)
    {
       
$str "-".$str;
    }
    return 
$str;
}
?>
2011-10-01 09:26:06
http://php5.kiev.ua/manual/ru/function.chr.html
to remove the ASCII control characters (except "line feed" and "tab") :

$tab_chr = array() ;
for($control = 0; $control < 32; $control++) {
    if ($control != 9 && $control != 10) {
        $tab_chr[]= chr($control) ;
    }
}
$tab_chr[]= chr(127) ;   
$string = str_replace($tab_chr, '', $string);
2012-03-01 11:47:53
http://php5.kiev.ua/manual/ru/function.chr.html

    Поддержать сайт на родительском проекте КГБ