For a modern large project, it is usually necessary to use CNC for pages. It has a positive effect on site indexing and results.

CNC - human understandable URL. In other words, this is the Latin transliterated part of the URL. We have already discussed the transliteration of the Russian alphabet into PHP. Bitrix has such a function; it is used, for example, when a new element or section of an information block is created, the symbolic code of this element or section is generated from its name. But what to do if the elements have already been created, but the symbolic codes are not registered. Let's look at a solution for this case:

"inc",); $arFilter = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "IBLOCK_LID" => "s1" //site name //"CODE" => "", //"CODE" => false); $arTransParams = array(//(maximum code length,case(lower,upper,do not change), //replace space with...,change other characters with...,remove extra replacement characters) "max_len" => 100 , "change_case" => "L", // "L" - toLower, "U" - toUpper, false - do not change "replace_space" => "-", "replace_other" => "-", "delete_repeat_replace" => true); if($arParams["TYPE_WORK"] == "section")(//for sections $db_elemens = CIBlockSection::GetList($arOrder, $arFilter, false); $db_elemens->NavStart($arParams["LIST_CNT"] ); echo "
"; while($ar_res = $db_elemens->GetNext()) ( $transName = CUtil::translit($ar_res["NAME"], "ru", $arTransParams); $arPropArray = Array("CODE" =>  $transName); $el = new CIBlockSection; $res = $el->Update($ar_res["ID"], $arPropArray); echo "result for ".$ar_res["NAME"]." is ".$transName."".($res?" and OK":" and failed")."\r\n"; ) echo "
"; )elseif($arParams["TYPE_WORK"] == "element")(//for elements $db_elemens = CIBlockElement::GetList($arOrder, $arFilter, false, array("nTopCount" => $arParams[" LIST_CNT"])); echo "
"; //for formatted output of the generation result while($obElement = $db_elemens->GetNextElement()) ( $ar_res = $obElement->GetFields(); $transName = CUtil::translit(trim($ar_res["NAME"  ]), "ru", $arTransParams);//function for generating a sim code from the name $arPropArray = Array("CODE" => $transName."-".$ar_res["ID"],);//k  add a "prefix" to the finished code - "-id" $el = new CIBlockElement; $res = $el->Update($ar_res["ID"], $arPropArray);//write the result, rewrite the code for this element echo $  transName."-".$ar_res["ID"]." 
"; //output the result ) echo "
"; } ?>

Run the PHP script several times in separate file or in the PHP console in the Bitrix admin panel until the messages about the successful generation of the symbolic code stop appearing. As a result, a Latin string in the form of the corresponding CNC will appear in the “Character code” field.

Children's skis: lyzhi-detskie
LEGO toy: igrushka-lego

Date of publication: 12/12/2011

The other day I needed to generate character codes for sections and elements of the “Furniture Catalog” information block in Bitrix.

What's happened character code in a section or element of an information block in Bitrix? The symbolic code of an information block element (section) in Bitrix means mnemonic identifier, which is a set of characters (Latin letters and numbers). This mnemonic identifier can be used to generate link addresses for dynamic pages on a site. For example, if the element “Sofa Cosmos” from the “Upholstered Furniture” section has the symbolic code “divan-cosmos”, then the link on the site may look like - “/catalog/myagkaya-mebel/divan-cosmos”

It’s done in one fell swoop, the main question was which method to transliterate. The first thought is to create some kind of your own method. I brushed it aside immediately. For the simple reason that - after all, how are these symbolic codes generated in the CMS? How are they generated? So there is a method! Yes, he is.

There is such a simple function that for some reason is still not described in the official Bitrix API documentation. (at the time of writing this article (December 2011) there was no mention in the documentation)

CUtil::translit($str, $lang, $params = array())

The function transliterates a string $str from the tongue $lang with parameters $params.

Array parameters $params:

In new versions of the kernel (I saw in 11.5.2) appeared new parameter "safe_chars", defaults to "", and also commented out "use_google", defaults to false.

EXAMPLE of use:

"-","replace_other"=>"-"); $trans = Cutil::translit($name,"ru",$arParams); echo $trans; ?>

UPD. The question was asked in the comments:
“Is it possible to simply write something in Bitrix so that the CNC is generated when importing information blocks?”
The question is incorrect and difficult for me to understand. But how special case I'll give you an example -
The task is to generate symbolic codes for products when importing a trade catalog from CSV.

"-","replace_other"=>"-"); $trans = Cutil::translit($name,"ru",$arParams); $arFields["CODE"] = $trans; ) ) ?>

Thus, when importing from a CSV file, a symbolic code will be automatically generated - a transliteration from the name.

Important UPD2.

People started asking questions about translit not working, see comments. I decided to figure it out, but I can’t reproduce the problem on any of my current or old projects - everything is OK for me. But people don't?

SOLUTION!

The problem is due to the encoding. Add to .htaccess:

php_value mbstring.func_overload 2
php_value mbstring.internal_encoding UTF-8

What to do if this doesn’t help? Go to the admin panel to the “site check” page and run the check. If the check still shows a message about incorrect encoding, don’t be upset. Either you need to contact the hoster to correct these settings, or forget about the standard translit function and write your own. (And also stop being surprised by all the other glitches due to coding).

Standard International Character Code, in which each character is encoded in seven bits. Topics telecommunications, basic concepts EN ISO 7...

code ISO-7- Standard International Character Code (ISO 646 1973), in which each character is encoded with seven digits. In the US, the version of this code is called ASCII. [E.S. Alekseev, A.A. Myachev. English-Russian explanatory dictionary on computer systems engineering. Moscow 1993]… … Technical Translator's Guide

Code (in digital computer)- Code in a digital computer, a conventional system of signs for presenting information in a digital computer. Each K. uses the signs of its own alphabet. For most K. alphabets are two-character or consist of letters of a two-character alphabet. K.’s physical form depends on the character... ...

IATA airline code- IATA airline code 2 or 3 character individual identifier assigned to the airline by the International Air Transport Association (IATA). This code is allocated in accordance with IATA resolution No. 762 by the headquarters of the association in ... ... Wikipedia

Code- I (French code, from Latin codex code of laws) a system of conventional signs (symbols) for transmitting, processing and storing (memorizing) various information. The final sequence of code characters is called a word. Number of different characters... ... Great Soviet Encyclopedia

RADIX-50- a symbolic code that allows you to write three characters in one 16-bit word. Used mainly on minicomputers, primarily the PDP 11 family (SM computer), for storing file names in file systems OS RT 11 and RSX 11, module names... ... Wikipedia

ESCON- (Enterprise Systems Connection) fiber channel interface that provides information exchange between the IBM zSeries server and peripheral devices(or another server). First used in archite servers... Wikipedia

address- noun, m., used. often Morphology: (no) what? addresses, what? address, (see) what? address, what? address, about what? about the address; pl. What? addresses, (no) what? addresses, what? addresses, (I see) what? addresses, what? addresses, about what? about addresses 1. Someone’s address... ... Dictionary Dmitrieva

task ID- A character code assigned to a task that is running or ready to run. [Domarev V.V. Safety information technologies. Systematic approach.] Topics information security EN task identifier ... Technical Translator's Guide

Pascal (programming language)- This article or section needs to be revised. There are no modules, OOP or other newfangled trends in Pascal. Descriptions of extensions should only be present in articles about the corresponding ... Wikipedia

Pascal (language)- Pascal Semantics: procedural Execution type: compiler Appeared in: 1970 Author(s): Niklaus Wirth Pascal is a high-level programming language general purpose. One of the most famous programming languages, widely... ... Wikipedia

Books

  • Linguistic and cultural method in phraseology. Codes of culture, M. L. Kovshova. The monograph is devoted to the linguocultural study of phraseological units - language signs that figuratively store and transmit from generation to generation the value systems of the national... Buy for 1053 UAH (Ukraine only)
  • Linguocultural method in phraseology Codes of culture, M. Kovshova. The monograph is devoted to the linguoculturological study of phraseological units - language signs that figuratively store and transmit from generation to generation the value systems of the national...

Typewritten text consists of printed characters - graphic symbols.
Graphic symbols are symbols that have a visible display in the text.
All graphic symbols are collected in a set of a single universal Unicode system.
Insert a Unicode graphic symbol into an html document
- the main and only purpose for this table.

You can insert a symbol into an HTML document in one of the following ways:

  1. copy the symbol image from the browser window to the window of your visual html editor
  2. copy the html code of the symbol directly into the code of the html document
Please understand that these are two different methods:
  1. insert visual into visual
  2. insert code into code.

The font for a symbol, its size and color in HTML can be set with code like:
CHARACTER_CODE
Where,
Arial - font,
10px - font size in pixels,
#ff0000 - font color code (red)

For example:
☎ - character font size 30px,
☎ - symbol font size 30px, color - red
☎ - character font size 20px,
☎ - symbol font size 10px.
Note Recommended fonts for inserting special characters are Arial, Verdana and Tahoma. These fonts display Unicode characters correctly and are themselves correctly supported by web applications.

  1. "Symbol"
    (visible symbol display)
    From this column you can copy the symbol image and paste it into the html text editor window. The symbol will be copied with a font size of 20px. After copying is complete, it may be necessary to individually adjust the font size directly to the copied character.
  2. "Name"
    (only for important or strange characters)
    Explanation of the purpose of the symbol, its scope, examples...
  3. "Mnemonics"
    A mnemonics is an alphabetic construction of the form ", denoting the alphabetic code of a character in HTML. It is inserted directly into the html code of an html document. Mnemonics are very popular among professional layout designers. They are perfectly memorized by humans and are supported by all html applications. Each mnemonics contains an alphabetic name (designation ) of its symbol and a service sign (&), which serves as a signal for the browser to read the code and is not displayed on the monitor screen.The name of each mnemonic is unique and easy to read, because it is derived from the English word that characterizes the symbol.

    Mnemonics (Greek) - the art of remembering something. Mnemonics are used to facilitate the perception of difficult-to-memorize information when the object of memorization is brought into an associative state with something.

  4. "Code"
    Code - the numeric decimal code of a character in HTML, like &. Inserted directly into the html code of an html document. The decimal code consists of a number indicating the serial number of the character in the Unicode system and several service characters (& and #), which serve as a signal for the browser to read the code and are not displayed on the monitor screen. The decimal code is widely used and used due to its versatility and ease of perception.

Control characters in HTML (XHTML)

Control characters in HTML (XHTML) are service characters of the HTML language that are used in the HTML layout of a web page. Any browser must support these characters, since without them it is impossible to display HTML text correctly. Control characters are not displayed in the text and, when entered directly from the keyboard, are interpreted by the browser as punctuation marks calling for some action to be performed when the page is drawn on the screen.

It is allowed to use control characters in ordinary texts, where they symbolize universal concepts and are interpreted by the browser as ordinary typographical characters. When using service symbols in HTML texts in this way, you need to enter not the value of the symbol itself, but its HTML code. Because, I repeat, otherwise the browser will perceive the service symbol as a call to action and will not correctly display the HTML text on the monitor screen.

Control characters and their HTML code are known and understood by all browsers without exception, which cannot be said, alas, about other characters that may be displayed incorrectly in different browsers or, even worse, not be displayed at all.

Syntax and punctuation

space of length N (regular space)
space of length M (longspace)
- soft hyphen (unprintable character) - ­
hyphen –
- dash of length N (regular dash) -
dash of length M (em dash)
. dot .
, comma ,
ellipses …
: colon :
; semicolon ;
! exclamation mark !
ǃ
? question mark ?
@ "dog" @
* "star" *
# "lattice" #
single upper left quote ‘
single upper right quote ’
single lower right quote ‚
double top left quote “
double upper right quote ”
double lower right quote &bdquo „
« double left corner quotation mark (Rus) « «
» double right corner quotation mark (Rus) » »
́ accent mark, example: Vasya ́
" apostrophe, example: You"I "
´ acute, example: Vasya ´ ´
paragraph (unprintable character)
§ paragraph § §
ˆ accent (inverted bird) ˆ ˆ
ˆ
˜ small tilde ˜ ˜
˜
¦ vertical dotted line ¦ ¦
( left parenthesis (
) right parenthesis )
left angle bracket
right angle bracket
left angle bracket, option
right angle bracket, option
[ square bracket left [
] square bracket right ]
/ slash - slash character /
\ backslash \
slash (division sign)
ǀ vertical bar ǀ
ǁ double vertical bar ǁ
overlining, example: Vasya‾vasya
¯ macron, example: Vasya¯vasya ¯ ¯

Trademarks and currency

+ plus + +
minus -
= equals =
± plus or minus ± ±
× multiplication sign × ×
÷ division sign ÷ ÷
dot operator (middle of line) ·
asterisk operator (middle of line)
tilde operator
. list marker (middle of line) . •
¹ superscript "1" ¹ ¹
² superscript "2" ² ²
³ superscript "3" ³ ³
Superscript and subscript in HTML (XHTML)
can be inserted using tags And , respectively:
NUMBER Superscript→ NUMBER Superscript
NUMBER Subscript→ NUMBER Subscript
½ fraction "one half" ½ ½
fraction "one third"
¼ fraction "one-fourth" ¼ ¼
¾ fraction "three quarters" ¾ ¾
number sign
% percent %
ppm ‰
° degrees ° °
prime (minutes, feet)
double prime (seconds, inches)
Example 1: 30° 25′ 12″
Example 2: 25′ 12
µ micro µ µ
π Pi π π
ƒ function sign
(not to be confused with "integral")
ƒ ƒ
ƒ
integral
crossed zero, empty set
(not to be confused with "diameter")
diameter (not to be confused with the crossed out Latin “o”)
ø Latin "o" diagonally crossed out ø ø
Ø Latin capital "O" diagonally crossed out Ø Ø
work mark
summation sign
radical
(square root or x root)
proportionally
infinity
corner
orthogonal (perpendicular)
sign "therefore"
approximately equal
almost equal
not equal
identically
less or equal
more or equal
logical AND
logical OR
plus sign in a circle
(direct amount)
multiplication sign in a circle
(cross product, arrow from observer)
ʘ dot in a circle
(arrow to observer)
ʘ

✵ ✵

If the code formatting is not specified in this section, the code should be formatted in accordance with PSR-2

  • Tab is used as indentation in the code.
  • The opening curly brace is on the same line.
  • The closing curly brace is on a new line.

Commenting code

Commenting PHP code is an integral part of it!

When commenting code, you should use PHPDoc comments.

For one-line explanatory comments in your code, you can use regular comments starting with // .

Variables

The basic rule for naming variables is that the name should be such that no comment is required to explain the purpose of the variable.

Prefixes

Variable names use the following prefixes:

  • ar- for arrays
  • db- for CDBResult
  • b- for Boolean variables, if it is not obvious from the name. The prefix is ​​required if a boolean value is used where a string value would normally be stored Y/N.

$arUserList = array(); $dbRes = CIBlockElement::GetByID($id); $bActive = false;

Variable names must not begin with an underscore.

Global Variables

Global variables are written in CAPITAL letters, separated by underscores.

Global $USER, $APPLICATION, $AR_MESSAGES.

The use of global variables is allowed only where absolutely necessary. Use what D7 gives you where it gives you it!

Local variables

Variables local to a script (function, method, class) always begin with a lowercase letter, words are separated by capitalization of the first character (camelCase).

This rule applies to abbreviations.
Those. BBC station is written $bbcStation; $arBbcStations; .

There is only one exception - ID is written in capitals.
Those. $sectionID , $arElementIDs .

$counter = 0; $bElementActive = false; $lastErrorMsg = ""; $ID = $_GET["ID"];

Auxiliary (temporary) variables

Variables used in FOR... FOREACH constructs can be called abbreviated if the code of the block in which they are used is viewed without scrolling the page.

For ($i = 0; $i< count($arRows); $i++) { // ... } foreach ($arElement as $k =>$v) ( // ... ) while ($arr = $dbRes->Fetch()) ( // ... )

Constants

Constant names are written in CAPITAL letters, words are separated by underscores. Due to the global scope, constants must be preceded by a short prefix (by the name of the module, component, template).

Bitrix character codes

Symbolic codes in Bitrix are needed for many things and therefore you should stick to the same name. The character code must be written in Latin letters, without numbers or special characters, and must reflect the essence of the information block, section or element.

Naming classes, methods, functions

  • Class names always start with capital letter. Words are separated by capitalization of the first letter. (CamelCase)
  • The names of methods and functions always begin with a small letter. Words are separated by capitalization of the first letter. (camelCase)

Due to the global scope of functions, their names should begin with a short prefix (by the name of a module, component, template).

Registration of management structures

A common rule for control structures is that a logical block of code is indented.

If the block does not fit on one screen, an indentation of at least two tabs is made. A large block of code assigned to one logical element should be separated by two or more blank lines and provided with opening and closing comments explaining the logic of the element.

Tools for auto-formatting code, setting parameters

[Plugins for SublimeText]

  • PhpDoc - Actually a plugin to support the PHPDoc format.
  • phpfmt - plugin for automatic formatting of php code (requires php installed).

Config for the plugin phpfmt.