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

  • Tabs are used as indents in the code.
  • The opening brace is on the same line.
  • Closing brace is on a new line.

Code commenting

Commenting PHP code is an integral part of it!

When commenting code, use PHPDoc comments.

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

Variables

The basic rule for variable naming 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 the name is not obvious. The prefix is ​​required if a boolean value is used where a string would normally be stored. Y/N.

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

Variable names must not start 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!

Local variables

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

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

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

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

Auxiliary (temporary) variables

Variables used in FOR... FOREACH constructs can be 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 an underscore. In connection with 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 their uniform names should be followed. The character code must be written in Latin letters, without numbers and special characters, and must reflect the essence of the info block, section or element.

Naming classes, methods, functions

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

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

Formation of control 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, at least two tabs are indented. Large block of code related to one logical element, must be separated by two or more empty lines and be provided with opening and closing comments explaining the logic of the element.

Tools for auto-formatting code, setting parameters

[Plugins for SublimeText]

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

Plugin config phpfmt.

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

You can insert a character into an html document in one of the following ways:

  1. copy the symbol image from the browser window into the window of your visual html editor
  2. copy the html code of a character directly into the code of the html document
We understand that these are two different ways:
  1. insert visual into visual
  2. embed code within code.

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

For example:
☎ - character font size 30px,
☎ - character font size 30px, color - red
☎ - character font size 20px,
☎ - character font size 10px.
Note. Recommended fonts for inserting special characters are Arial, Verdana and Tahoma. These fonts correctly display Unicode characters and are in turn properly 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 completed, it may be necessary to individually adjust the font size directly for the copied character.
  2. "Name"
    (only for important or obscure characters)
    Explanation of the purpose of the symbol, its scope, examples ...
  3. "Mnemonics"
    A mnemonic is a letter construct of the form ", denoting the letter code of a character in HTML. It is inserted directly into the html code of an html document. Mnemonics are very popular among professional typesetters. They are perfectly remembered by a person and are supported by all html applications. Each mnemonic contains a letter name (designation ) of its symbol and a service character (&), which serves as a signal to read the code for the browser and is not displayed on the monitor screen.The name of each mnemonic is unique and easy to read, because it is formed from the English word that characterizes the symbol.

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

  4. "The code"
    Code - numeric decimal code character in HTML, of the form &. Inserted directly into the html code of an html document. Numeric decimal code consists of a number denoting serial number character in the Unicode system and several service characters (& and #), which serve as a signal to read the code for the browser and are not displayed on the monitor screen. The numerical 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 the service symbols of the HTML language that are used in the HTML layout of a web page. These characters must be supported by any browser, because without them it is impossible to display HTML text correctly. Control characters are not displayed in the text and, when directly entered from the keyboard, are interpreted by the browser as punctuation marks, calling for some action 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 treated by the browser as ordinary typographic characters. With this use of service symbols in HTML texts, it is required to enter not the value of the symbol itself, but its HTML code. For, I repeat, otherwise the browser will perceive the service character 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 not be displayed correctly in different browsers or, even worse, not displayed at all.

Syntax and punctuation

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

Trademarks and currency

+ a plus + +
minus -
= equals =
± plus or minus ± ±
× multiplication sign × ×
÷ division sign ÷ ÷
dot operator (middle of string) ·
asterisk operator (middle of string)
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" ¼ ¼
¾ three-quarter fraction ¾ ¾
number sign
% percent %
ppm ‰
° degrees ° °
stroke (minutes, feet)
double stroke (seconds, inches)
Example 1: 30° 25′ 12″
Example 2: 25′ 12
µ micro µ µ
π Pi π π
ƒ function sign
(not to be confused with "integral")
ƒ ƒ
ƒ
integral
crossed out zero, empty set
(not to be confused with "diameter")
diameter (not to be confused with the crossed out Latin "o")
ø latin "o" diagonally crossed ø ø
Ø latin capital "O" diagonally slashed Ø Ø
product mark
summation sign
radical
(square root or x root)
proportionately
infinity
corner
orthogonal (perpendicular)
"therefore" sign
approximately equal to
almost equal
not equal
identically
less or equal
more or equal
logical AND
logical OR
plus sign in a circle
(direct sum)
sign "multiplication in a circle"
(cross product, arrow from observer)
ʘ dot in a circle
(arrow at observer)
ʘ

✵ ✵

For a modern large project, as a rule, it is mandatory to use cnc for pages. It has a positive effect on the indexing of the site and the issue in the results.

CNC - human understandable url. In other words, this is the part of the url transliterated in Latin. We have already analyzed the transliteration of the Russian alphabet into php. Bitrix has such a function, it is used, for example, when creating new element or infoblock section, the character 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 the 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 to generate symbol code from name $arPropArray = Array("CODE" => $transName."-".$ar_res["ID"],);//to  add "prefix" - "-id" to the finished code $el = new CIBlockElement; $res = $el->Update($ar_res["ID"], $arPropArray);//write the result, overwrite the code for this element echo $  transName."-".$ar_res["ID"]." 
"; //output the result ) echo "
"; } ?>

Run the php script several times in a separate file or in the php-console in the Bitrix admin panel until you no longer receive messages about the successful generation of the character code. As a result, a Latin string will appear in the "Character code" field in the form of the corresponding NC.

Skis for children: lyzhi-detskie
LEGO toy: toyrushka-lego

Publication date: 12/12/2011

It was required the other day to generate character codes for sections and elements of the "Furniture Catalog" infoblock in Bitrix.

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

It is done in a swoop, the main question was what method to transliterate. The first thought is really to compose some kind of method. She dismissed it right away. For the simple reason that - after all, how are these character codes generated in the CMS? Also how they are generated. So there is a method! Yes, he is.

There is such simple function, which for some reason has not yet been described in official documentation by Bitrix API. (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.

Parameters in an array $params:

In new versions of the kernel (I saw in 11.5.2) appeared new parameter "safe_chars", defaults to "", 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, in a simple way, where to prescribe something in Bitrix so that the CNC generates when importing infoblocks works?"
The question is incorrect, and it is difficult for me to understand it. But as a special case, I will give such an example -
the task is to generate character codes for goods 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.

They began to ask questions that transliteration does not work, 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 with me. But people don't?

SOLUTION!

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

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

What to do if this does not help? We go to the admin panel on the "site check" page, start the check. If a message about an incorrect encoding remains in the check, don't worry. Either you need to contact the host to fix these settings, or forget about the standard transliteration function and write your own. (And also stop being surprised by all the other glitches due to encoding).

A standard international character code in which each character is encoded with seven bits. Telecommunication topics, basic concepts EN ISO 7 ...

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

Code (in digital computer)- Code in a computer, a conventional system of signs for representing information in a computer. Each K. uses the characters of his alphabet. For the majority of alphabets, alphabets are two-character or consist of letters from a two-character alphabet. The physical form of K. depends on the character ... ...

IATA airline code- IATA airline code 2 or 3 character unique identifier assigned to the airline by the International Association air transport(IATA). This code is allocated in accordance with IATA Resolution No. 762 by the association's headquarters in ... ... Wikipedia

The code- I (French code, from Latin codex code of laws) a system of conventional signs (symbols) for the transmission, processing and storage (memorization) of various information. The final sequence of code characters is called a word. The number of different characters, ... ... Great Soviet Encyclopedia

RADIX-50- a character code that allows you to write three characters in one 16-bit word. It was used mainly on minicomputers, primarily of the PDP 11 family (SM computers), 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 peripherals(or another server). First used in archite servers ... Wikipedia

address- n., m., use. often Morphology: (no) what? addresses for what? address, (see) what? address of what? address about what? about the address; pl. what? addresses, (no) what? addresses for what? addresses, (see) what? addresses, what? addresses about what? about addresses 1. Someone's address ... ... Dictionary Dmitrieva

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

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

Pascal (language)- Pascal Semantics: procedural Execution type: compiler Introduced in: 1970 Author(s): Niklaus Wirth Pascal is a general-purpose high-level programming language. 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 linguoculturological study of phraseological units - language signs that figuratively store and transmit from generation to generation the value orientations of the national ... Buy for 1053 UAH (only Ukraine)
  • Linguistic and cultural method in phraseology Codes of culture, Kovshova M.