cvs: phpdoc-ru /language types.xml
| From: | Kai Liki | Date: | Mon, 03 Mar 2003 11:01:45 +0000 |
| Subject: | cvs: phpdoc-ru /language types.xml | ||
| Groups: | php.doc.ru | ||
| Request: | Send a blank email to doc-ru+get-80@lists.php.net to get a copy of this message | ||
kai Mon Mar 3 06:01:45 2003 EDT
Modified files:
/phpdoc-ru/language types.xml
Log:
Half of file translated
Index: phpdoc-ru/language/types.xml diff -u phpdoc-ru/language/types.xml:1.2 phpdoc-ru/language/types.xml:1.3 --- phpdoc-ru/language/types.xml:1.2 Tue Jan 28 07:27:04 2003 +++ phpdoc-ru/language/types.xml Mon Mar 3 06:01:40 2003 @@ -1,20 +1,21 @@ <?xml version="1.0" encoding="windows-1251"?> -<!-- EN-Revision: 1.98 Maintainer: Kai Status: in-progress --> -<!-- $Revision: 1.2 $ --> +<!-- EN-Revision: 1.98 Maintainer: Kai Status: not yet ready --> +<!-- $Revision: 1.3 $ --> <chapter id="language.types"> <title>Òèïû</title> <!-- - Çàìå÷àíèå: Ïîñëåäíåå èçìåíåíèå çàìåòêè: 2003-09-01 - resource ïåðåâåë êàê èñòî÷íèê + Çàìå÷àíèå: Ïîñëåäíåå èçìåíåíèå çàìåòêè: 2003-03-03 + resource - ðåñóðñ control structure = óïðàâëÿþùàÿ êîíñòðóêöèÿ language.types.string.conversion = Êîíâåðòàöèÿ ñòðîê â ÷èñëà Arbitrary Precision Mathematics Functions=ìàòåìàòè÷åñêèå ôóêöèè ïðîèçâîëüíîé òî÷íîñòè String conversion to numbers = Êîíâåðòàöèÿ ñòðîê â ÷èñëà language.types.integer.casting = - è äðóãèå ññûëêè - óòî÷íèòü - heredoc-ñèíòàêñèñ - êàê ïåðåâåñòè? + è äðóãèå ññûëêè + heredoc-ñèíòàêñèñ Escaped characters + language.operators.string --> <sect1 id="language.types.intro"> @@ -79,7 +80,7 @@ <listitem> <simpara> - <link linkend="language.types.resource">èñòî÷íèê</link> + <link linkend="language.types.resource">ðåñóðñ</link> </simpara> </listitem> @@ -744,48 +745,47 @@ <title>Heredoc</title> <simpara> Äðóãîé ñïîñîá îïðåäåëåíèÿ ñòðîê - ýòî èñïîëüçîâàíèå - heredoc-ñèíòàêñèñà ("<<<"). One should provide an identifier after - <literal><<<</literal>, then the string, and then the - same identifier to close the quotation. + heredoc-ñèíòàêñèñà ("<<<"). Ïîñëå + <literal><<<</literal> íåîáõîäèìî óêàçàòü èäåíòèôèêàòîð, + çàòåì èäåò ñòðîêà, à ïîòîì ýòîò æå èäåíòèôèêàòîð, çàêðûâàþùèé âñòàâêó. </simpara> <simpara> - The closing identifier <emphasis>must</emphasis> begin in the - first column of the line. Also, the identifier used must follow - the same naming rules as any other label in PHP: it must contain - only alphanumeric characters and underscores, and must start with - a non-digit character or underscore. + Çàêðûâàþùèé èäåíòèôèêòîð <emphasis>äîëæåí</emphasis> íà÷èíàòüñÿ â + ïåðâîì ñòîëáöå ñòðîêè. Êðîìå òîãî, èäåíòèôèêàòîð äîëæåí + ñîîòâåòñòâîâàòü òåì æå ïðàâèëàì èìåíîâàíèÿ, ÷òî è âñå îñòàëüíûå + ìåòêè â PHP: ñîäåðæàòü òîëüêî áóêâåííî-öèôðîâûå ñèìâîëû è çíàê + ïîä÷åðêèâàíèÿ, è äîëæåí íà÷èíàòüñÿ ñ íåöèôðû èëè çíàêà ïîä÷åðêèâàíèÿ. </simpara> <warning> <simpara> - It is very important to note that the line with the closing - identifier contains no other characters, except - <emphasis>possibly</emphasis> a semicolon (<literal>;</literal>). - That means especially that the identifier - <emphasis>may not be indented</emphasis>, and there - may not be any spaces or tabs after or before the semicolon. + Âàæíî îòìåòèòü, ÷òî ñòðîêà ñ çàêðûâàþùèì èäåíòèôèêàòîðîì íå ñîäåðæèò + äðóãèõ ñèìâîëîâ, çà èñêëþ÷åíèåì, <emphasis>âîçìîæíî</emphasis>, + òî÷êè ñ çàïÿòîé (<literal>;</literal>). Ýòî îçíà÷àåò, ÷òî èäåíòèôèêàòîð + <emphasis>íå äîëæåí ââîäèòüñÿ ñ îòñòóïîì</emphasis> è ÷òî íå ìîæåò + áûòü íèêàêèõ ïðîáåëîâ èëè çíàêîâ òàáóëÿöèè äî èëè ïîñëå òî÷êè ñ çàïÿòîé. </simpara> </warning> <para> - Heredoc text behaves just like a double-quoted string, without - the double-quotes. This means that you do not need to escape quotes - in your here docs, but you can still use the escape codes listed - above. Variables are expanded, but the same care must be taken - when expressing complex variables inside a here doc as with - strings. + Heredoc-òåêñò âåä¸ò ñåáÿ òàê æå, êàê è ñòðîêà â äâîéíûõ êàâû÷êàõ, + íî áåç íèõ. Ýòî îçíà÷àåò, ÷òî âàì íåò íåîáõîäèìîñòè ìíåìîíèçèðîâàòü + êàâû÷êè â heredoc, íî âû ïî-ïðåæíåìó ìîæåòå èñïîëüçîâàòü + âûøåïåðå÷èñëåííûå êîäû-ìíåìîíèêè. Ïåðåìåííûå îáðàáàòûâàþòñÿ, íî + ñ ïðèìåíåíèåì ñëîæíûõ ïåðåìåííûõ âíóòðè heredoc íóæíî áûòü òàêæå + âíèìàòåëüíûì, êàê è ïðè ðàáîòå ñî ñòðîêàìè. <example> - <title>Heredoc string quoting example</title> + <title>Ïðèìåð îïðåäåëåíèÿ heredoc-ñòðîêè</title> <programlisting role="php"> <![CDATA[ <?php $str = <<<EOD -Example of string -spanning multiple lines -using heredoc syntax. +Ïðèìåð ñòðîêè, +îõâàòûâàþùåé íåñêîëüêî ñòðî÷åê +ñ èñïîëüçîâàíèåì heredoc-ñèíòàêñèñà. EOD; -/* More complex example, with variables. */ +/* Áîëåå ñëîæíûé ïðèìåð ñ ïåðåìåííûìè. */ class foo { var $foo; @@ -799,12 +799,12 @@ } $foo = new foo(); -$name = 'MyName'; +$name = 'ÌîåÈìÿ'; echo <<<EOT -My name is "$name". I am printing some $foo->foo. -Now, I am printing some {$foo->bar[1]}. -This should print a capital 'A': \x41 +Ìåíÿ çîâóò "$name". ß ïå÷àòàþ $foo->foo. +Òåïåðü ÿ âûâîæó {$foo->bar[1]}. +Ýòî äîëæíî âûâåñòè çàãëàâíóþ áóêâó 'A': \x41 EOT; ?> ]]> @@ -814,56 +814,53 @@ <note> <para> - Heredoc support was added in PHP 4. + Ïîääåðæêà heredoc áûëà äîáàâëåíà â PHP 4. </para> </note> </sect3> <sect3 id="language.types.string.parsing"> - <title>Variable parsing</title> + <title>Îáðàáîòêà ïåðåìåííûõ</title> <simpara> - When a string is specified in double quotes or with - heredoc, variables are parsed within it. + Åñëè ñòðîêà îïðåäåëÿåòñÿ â äâîéíûõ êàâû÷êàõ, ëèáî ïðè ïîìîùè + heredoc, ïåðåìåííûå âíóòðè íåå îáðàáàòûâàþòñÿ. </simpara> <simpara> - There are two types of syntax, a - <link linkend="language.types.string.parsing.simple">simple</link> - one and a - <link linkend="language.types.string.parsing.complex">complex</link> - one. - The simple syntax is the most common and convenient, it provides a way - to parse a variable, an array value, or an object property. + Ñóùåñòâóåò äâà òèïà ñèíòàêñèñà - + <link linkend="language.types.string.parsing.simple">ïðîñòîé</link> è + <link linkend="language.types.string.parsing.complex">ñëîæíûé</link>. + Ïðîñòîé ñèíòàêñèñ áîëåå ëåãîê è óäîáåí, îí äàåò âîçìîæíîñòü + îáðàáîòêè ïåðåìåííîé, çíà÷åíèÿ ìàññèâà èëè ñâîéñòâà îáúåêòà. </simpara> <simpara> - The complex syntax was introduced in PHP 4, and can be recognised - by the curly braces surrounding the expression. + Ñëîæíûé ñèíòàêñèñ áûë ââåäåí â PHP 4 è ìîæåò áûòü ðàñïîçíàí + ïî ôèãóðíûì ñêîáêàì, îêðóæàþùèõ âûðàæåíèå. </simpara> <sect4 id="language.types.string.parsing.simple"> - <title>Simple syntax</title> + <title>Ïðîñòîé ñèíòàêñèñ</title> <simpara> - If a dollar sign (<literal>$</literal>) is encountered, the - parser will greedily take as much tokens as possible to form a - valid variable name. Enclose the variable name in curly - braces if you want to explicitly specify the end of the name. + Åñëè èíòåðïðåòàòîð âñòðå÷àåò çíàê äîëëàðà (<literal>$</literal>), îí + çàõâàòûâàåò ñòîëüêî ñèìâîëîâ, ñêîëüêî âîçìîæíî, ÷òîáû ñôîðìèðîâàòü + ïðàâèëüíîå èìÿ ïåðåìåííîé. Åñëè âû õîòèòå òî÷íî îïðåäåëèòü êîíåö èìåíè, + çàêëþ÷àéòå èìÿ ïåðåìåííîé â ôèãóðíûå ñêîáêè. </simpara> <informalexample> <programlisting role="php"> <![CDATA[ $beer = 'Heineken'; -echo "$beer's taste is great"; // works, "'" is an invalid character for varnames -echo "He drank some $beers"; // won't work, 's' is a valid character for varnames -echo "He drank some ${beer}s"; // works +echo "$beer's taste is great"; // ðàáîòàåò, "'" ýòî íåâåðíûé ñèìâîë äëÿ èìåíè ïåðåìåííîé +echo "He drank some $beers"; // íå ðàáîòàåò, 's' ýòî âåðíûé ñèìâîë äëÿ èìåíè ïåðåìåííîé +echo "He drank some ${beer}s"; // ðàáîòàåò ]]> </programlisting> </informalexample> <simpara> - Similarly, you can also have an array index or an object - property parsed. With array indices, the closing square bracket - (<literal>]</literal>) marks the end of the index. For - object properties the same rules apply as to simple variables, - though with object properties there doesn't exist a trick like - the one with variables. + Òî÷íî òàêæå ìîãóò áûòü îáðàáîòàíû ýëåìåíò ìàññèâà èëè ñâîéñòâî + îáúåêòà.  ýëåìåíòàõ ìàññèâà çàêðûâàþùàÿ êâàäðàòíàÿ ñêîáêà + (<literal>]</literal>) îáîçíà÷àåò êîíåö îïðåäåëåíèÿ ýëåìåíòà. + Äëÿ ñâîéñòâ îáúåêòà ïðèìåíÿþòñÿ òå æå ïðàâèëà, ÷òî è äëÿ ïðîñòûõ + ïåðåìåííûõ, õîòÿ ñ íèìè íåâîçìîæåí òðþê, êàê ñ ïåðåìåííûìè. <!-- XXX isn't &true; :(, this would be the trick Also, the same trick with curly-braces works if you @@ -876,12 +873,12 @@ <![CDATA[ $fruits = array('strawberry' => 'red', 'banana' => 'yellow'); -// note that this works differently outside string-quotes +// Çàìåòüòå, ÷òî âíå êàâû÷åê ýòà êîíñòðóêöèÿ ðàáîòàåò ïî-äðóãîìó echo "A banana is $fruits[banana]."; echo "This square is $square->width meters broad."; -// Won't work. For a solution, see the complex syntax. +// Íå ðàáîòàåò. Äëÿ ðåøåíèÿ ñì. ñëîæíûé ñèíòàêñèñ. echo "This square is $square->width00 centimeters broad."; ]]> @@ -894,41 +891,42 @@ </programlisting> </informalexample> <simpara> - For anything more complex, you should use the complex syntax. + Äëÿ ÷åãî-ëèáî áîëåå ñëîæíîãî âû äîëæíû èñïîëüçîâàòü ñëîæíûé ñèíòàêñèñ. </simpara> </sect4> <sect4 id="language.types.string.parsing.complex"> - <title>Complex (curly) syntax</title> + <title>Ñëîæíûé (ôèãóðíûé) ñèíòàêñèñ</title> <simpara> - This isn't called complex because the syntax is complex, - but because you can include complex expressions this way. + Îí íàçûâàåòñÿ ñëîæíûì íå ïîòîìó, ÷òî òðóäåí â ïîíèìàíèè, + à ïîòîìó ÷òî ïîçâîëÿåò èñïîëüçîâàòü ñëîæíûå âûðàæåíèÿ. </simpara> <simpara> - In fact, you can include any value that is in the namespace - in strings with this syntax. You simply write the expression - the same way as you would outside the string, and then include - it in { and }. Since you can't escape '{', this syntax will - only be recognised when the $ is immediately following the {. - (Use "{\$" or "\{$" to get a literal "{$"). - Some examples to make it clear: + Ôàêòè÷åñêè, âû ìîæåòå âêëþ÷èòü ëþáîå çíà÷åíèå, íàõîäÿùååñÿ â + ïðîñòðàíñòâå èìåíè â ñòðîêå ñ ýòèì ñèíòàêñèñîì. Âû ïðîñòî + çàïèñûâàåòå âûðàæåíèå òàêèì æå îáðàçîì, êàê è âíå ñòðîêè, à + çàòåì çàêëþ÷àåòå åãî â { è }. Ïîñêîëüêó âû íå ìîæåòå çàìåíèòü + ìíåìîíèêîé '{', ýòîò ñèíòàêñèñ áóäåò ðàñïîçíàâàòüñÿ òîëüêî + êîãäà $ ñëåäóåò íåïîñðåäñòâåííî çà {. (Èñïîëüçóéòå "{\$" èëè + "\{$" ÷òîáû îòîáðàçèòü "{$"). + Íåñêîëüêî ïîÿñíÿþùèõ ïðèìåðîâ: </simpara> <informalexample> <programlisting role="php"> <![CDATA[ $great = 'fantastic'; -echo "This is { $great}"; // won't work, outputs: This is { fantastic} -echo "This is {$great}"; // works, outputs: This is fantastic -echo "This square is {$square->width}00 centimeters broad."; -echo "This works: {$arr[4][3]}"; - -// This is wrong for the same reason -// as $foo[bar] is wrong outside a string. -echo "This is wrong: {$arr[foo][3]}"; - -echo "You should do it this way: {$arr['foo'][3]}"; -echo "You can even write {$obj->values[3]->name}"; -echo "This is the value of the var named $name: {${$name}}"; +echo "This is { $great}"; // íå áóäåò ðàáîòàòü, âûâåäåò: This is { fantastic} +echo "This is {$great}"; // ðàáîòàåò, âûâåäåò: This is fantastic +echo "Ýòîò êâàäðàò øèðèíîé {$square->width}00 ñàíòèìåòðîâ."; +echo "Ýòî ðàáîòàåò: {$arr[4][3]}"; + +// Ýòî íåâåðíî ïî òîé æå ïðè÷èíå, +// ÷òî è $foo[bar] íåâåðíî âíå ñòðîêè. +echo "Ýòî íåïðàâèëüíî: {$arr[foo][3]}"; + +echo "Ñëåäóåò äåëàòü ýòî òàê: {$arr['foo'][3]}"; +echo "Âû ìîæåòå äàæå çàïèñàòü {$obj->values[3]->name}"; +echo "Ýòî çíà÷åíèå ïåðåìåííîé ïî èìåíè $name: {${$name}}"; ]]> <!-- maybe it's better to leave this out?? // this works, but i disencourage its use, since this is NOT @@ -942,31 +940,32 @@ </sect3> <sect3 id="language.types.string.substr"> - <title>String access by character</title> + <title>Äîñòóï ê ñèìâîëó â ñòðîêå</title> <para> - Characters within strings may be accessed by specifying the - zero-based offset of the desired character after the string - in curly braces. + Ñèìâîëû â ñòðîêàõ ìîæíî èñïîëüçîâàòü, îïðåäåëèâ èõ ñìåùåíèå + îòíîñèòåëüíî íà÷àëà ñòðîêè, íà÷èíàÿ ñ íóëÿ, â ôèãóðíûõ + ñêîáêàõ ïîñëå ñòðîêè. </para> <note> <simpara> - For backwards compatibility, you can still use array-braces - for the same purpose. However, this syntax is deprecated as - of PHP 4. + Äëÿ îáåñïå÷åíèÿ îáðàòíîé ñîâìåñòèìîñòè, âû ïî-ïðåæíåìó èìååòå + âîçìîæíîñòü èñïîëüçîâàòü â òåõ æå öåëÿõ ñêîáêè ìàññèâà. + Îäíàêî, íà÷èíàÿ ñ PHP 4, ýòîò ñèíòàêñèñ íåæåëàòåëåí ê + èñïîëüçîâàíèþ. </simpara> </note> <para> <example> - <title>Some string examples</title> + <title>Íåñêîëüêî ïðèìåðîâ ñòðîê</title> <programlisting role="php"> <![CDATA[ <?php -// Get the first character of a string -$str = 'This is a test.'; +// Ïîëó÷åíèå ïåðâîãî ñèìâîëà ñòðîêè +$str = 'Ýòî òåñò.'; $first = $str{0}; -// Get the last character of a string. -$str = 'This is still a test.'; +// Ïîëó÷åíèå ïîñëåäíåãî ñèìâîëà ñòðîêè +$str = 'Ýòî âñå åùå òåñò.'; $last = $str{strlen($str)-1}; ?> ]]> @@ -978,160 +977,160 @@ </sect2><!-- end syntax --> <sect2 id="language.types.string.useful-funcs"> - <title>Useful functions and operators</title> + <title>Ïîëåçíûå ôóíêöèè è îïåðàòîðû</title> <para> - Strings may be concatenated using the '.' (dot) operator. Note - that the '+' (addition) operator will not work for this. Please - see <link linkend="language.operators.string">String - operators</link> for more information. + Ñòðîêè ìîãóò áûòü îáúåäèíåíû ïðè ïîìîùè îïåðàòîðà '.' (òî÷êà). + Îáðàòèòå âíèìàíèå, îïåðàòîð ñëîæåíèÿ '+' çäåñü íå ðàáîòàåò. + Äîïîëíèòåëüíóþ èíôîðìàöèþ ñìîòðèòå â ðàçäåëå <link + linkend="language.operators.string">Ñòðîêîâûå îïåðàòîðû</link>. </para> <para> - There are a lot of useful functions for string modification. + Äëÿ ìîäèôèêàöèè ñòðîê ñóùåñòâóåò ìíîæåñòâî ïîëåçíûõ ôóíêöèé. </para> <simpara> - See the <link linkend="ref.strings">string functions section</link> - for general functions, the regular expression functions for - advanced find&replacing (in two tastes: - <link linkend="ref.pcre">Perl</link> and - <link linkend="ref.regex">POSIX extended</link>). + Îñíîâíûå ôóíêöèè îïèñàíû â ðàçäåëå + <link linkend="ref.strings">ñòðîêîâûõ ôóíêöèé</link>, ôóíêöèè + ðåãóëÿðíûõ âûðàæåíèé äëÿ ðàñøèðåííîãî ïîèñêà è çàìåíû (â äâóõ ÷àñòÿõ: + <link linkend="ref.pcre">Perl</link> è <link + linkend="ref.regex">POSIX ðàñøèðåííûé</link>). </simpara> <simpara> - There are also <link linkend="ref.url">functions for URL-strings</link>, - and functions to encrypt/decrypt strings - (<link linkend="ref.mcrypt">mcrypt</link> and - <link linkend="ref.mhash">mhash</link>). + Òàêæå ñóùåñòâóþò <link linkend="ref.url">ôóíêöèè äëÿ URL-ñòðîê</link>, + è ôóíêöèè äëÿ øèôðîâàíèÿ/äåøèôðîâàíèÿ ñòðîê (<link + linkend="ref.mcrypt">mcrypt</link> è <link + linkend="ref.mhash">mhash</link>). </simpara> <simpara> - Finally, if you still didn't find what you're looking for, - see also the <link linkend="ref.ctype">character type functions</link>. + Íàêîíåö, åñëè âû âñå åùå íå íàøëè, ÷òî èñêàëè, ñìîòðèòå òàêæå + <link linkend="ref.ctype">ôóíêöèè äëÿ ñèìâîëüíîãî òèïà</link>. </simpara> </sect2> <sect2 id="language.types.string.casting"> - <title>Converting to string</title> + <title>Êîíâåðòàöèÿ â ñòðîêó</title> <para> - You can convert a value to a string using the <literal>(string)</literal> - cast, or the <function>strval</function> function. String conversion - is automatically done in the scope of an expression for you where a - string is needed. This happens when you use the <function>echo</function> - or <function>print</function> functions, or when you compare a variable - value to a string. + Âû ìîæåòå êîíâåðòèðîâàòü çíà÷åíèå â ñòðîêó, èñïîëüçóÿ ïðèâåäåíèå + <literal>(string)</literal>, ëèáî ôóíêöèþ <function>strval</function>. +  âûðàæåíèÿõ, ãäå íåîáõîäèìà ñòðîêà, êîíâåðòàöèÿ ïðîèñõîäèò àâòîìàòè÷åñêè. + Ýòî ïðîèñõîäèò, êîãäà âû èñïîëüçóåòå ôóíêöèè <function>echo</function> + èëè <function>print</function>, ëèáî êîãäà âû ñðàâíèâàåòå çíà÷åíèå + ïåðåìåííîé ñî ñòðîêîé. </para> <para> - A boolean &true; value is converted to the string <literal>"1"</literal>, - the &false; value is represented as <literal>""</literal> (empty string). - This way you can convert back and forth between boolean and string values. + Ëîãè÷åñêîå çíà÷åíèå &true; êîíâåðòèðóåòñÿ â ñòðîêó <literal>"1"</literal>, + à çíà÷åíèå &false; ïðåäñòàâëÿåòñÿ êàê <literal>""</literal> (ïóñòàÿ ñòðîêà). + Ýòèì ñïîñîáîì âû ìîæåòå êîíâåðòèðîâàòü çíà÷åíèÿ â îáå ñòîðîíû èç áóëåâà + òèïà â ñòðîêîâûé è íàîáîðîò. </para> <para> - An integer or a floating point number is converted to a string - representing the number with its digits (includig the exponent part - for floating point numbers). + Öåëîå èëè ÷èñëî ñ ïëàâàþùåé òî÷êîé êîíâåðòèðóåòñÿ â ñòðîêó, ïðåäñòàâëåííóþ + ÷èñëîì, ñîñòîÿùèì èç åãî öèôð (âêëþ÷àÿ ïîêàçàëòåëü ñòåïåíè äëÿ ÷èñåë ñ + ïëàâàþùåé òî÷êîé). </para> <para> - Arrays are always converted to the string <literal>"Array"</literal>, - so you cannot dump out the contents of an array with <function>echo</function> - or <function>print</function> to see what is inside them. See the information - below for more tips. + Ìàññèâû âñåãäà êîíâåðòèðóþòñÿ â ñòðîêó <literal>"Array"</literal>, + òàê ÷òî âû íå ìîæåòå îòîáðàçèòü ñîäåðæèìîå ìàññèâà, èñïîëüçóÿ + <function>echo</function> èëè <function>print</function>, ÷òîáû óçíàòü, + ÷òî îí ñîäåðæèò. Äîïîëíèòåëüíûå ñîâåòû âû ìîæåòå íàéòè íèæå. </para> <para> - Objects are always converted to the string <literal>"Object"</literal>. - If you would like to print out the member variable values of an object - for debugging reasons, read the paragraphs below. If you would - like to find out the class name of which an object is an instance of, - use <function>get_class</function>. + Îáúåêòû âñåãäà êîíâåðòèðóþòñÿ â ñòðîêó <literal>"Object"</literal>. + Åñëè âû õîòèòå âûâåñòè çíà÷åíèå ïåðåìåííîé-÷ëåíà îáúåêòà ïî ïðè÷èíå + îòëàäêè, ïðî÷òèòå ñëåäóþùèå àáçàöû. Åñëè âû õîòèòå ïîëó÷èòü èìÿ êëàññà + òðåáóåìîãî îáúåêòà, èñïîëüçóéòå ôóíêöèþ <function>get_class</function>. </para> <para> - Resources are always converted to strings with the structure - <literal>"Resource id #1"</literal> where <literal>1</literal> is - the unique number of the resource assigned by PHP during runtime. - If you would like to get the type of the resource, use + Ðåñóðñû âñåãäà êîíâåðòèðóþòñÿ â ñòðîêè ñî ñòðóêòóðîé + <literal>"Resource id #1"</literal>, ãäå <literal>1</literal> - ýòî + óíèêàëüíûé íîìåð ðåñóðñà, ïðèñâîåííûé åìó PHP âî âðåìÿ âûïîëíåíèÿ. + Åñëè âû õîòèòå ïîëó÷èòü òèï ðåñóðñà, èñïîëüçóéòå ôóíêöèþ <function>get_resource_type</function>. </para> <para> - &null; is always converted to an empty string. + &null; âñåãäà êîíâåðòèðóåòñÿ â ïóñòóþ ñòðîêó. </para> <para> - As you can see above, printing out the arrays, objects or resources does not - provide you any useful information about the values themselfs. Look at the - functions <function>print_r</function> and <function>var_dump</function> - for better ways to print out values for debugging. + Êàê âû ìîãëè âèäåòü âûøå, âûâîä ìàññèâîâ, îáúåêòîâ èëè ðåñóðñîâ íå + ïðåäîñòàâëÿåò âàì íèêàêîé ïîëåçíîé èíôîðìàöèè î ñàìèõ çíà÷åíèÿõ. Áîëåå + ïîäõîäÿùèé ñïîñîá âûâîäà çíà÷åíèé äëÿ îòëàäêè - èñïîëüçîâàòü ôóíêöèè + <function>print_r</function> è <function>var_dump</function>. </para> <para> - You can also convert PHP values to strings to store them permanently. This - method is called serialization, and can be done with the function - <function>serialize</function>. You can also serialize PHP values to - XML structures, if you have <link linkend="ref.wddx">WDDX</link> support - in your PHP setup. + Âû òàêæå ìîæåòå êîíâåðòèðîâàòü çíà÷åíèÿ PHP â ñòðîêè äëÿ ïîñòîÿííîãî + õðàíåíèÿ. Ýòîò ìåòîä íàçûâàåòñÿ ñåðèàëèçàöèåé è ìîæåò áûòü âûïîëíåí + ïðè ïîìîùè ôóíêöèè <function>serialize</function>. Êðîìå òîãî, åñëè â + âàøåé óñòàíîâêå PHP åñòü ïîääåðæêà <link linkend="ref.wddx">WDDX</link>, + âû ìîæåòå ñåðèàëèçîâàòü çíà÷åíèÿ PHP â ñòðóêòóðû XML. </para> </sect2> <sect2 id="language.types.string.conversion"> - <title>String conversion to numbers</title> + <title>Êîíâåðòàöèÿ ñòðîê â ÷èñëà</title> <simpara> - When a string is evaluated as a numeric value, the resulting - value and type are determined as follows. + Åñëè ñòðîêà ðàñïîçíàåòñÿ êàê ÷èñëîâîå çíà÷åíèå, ðåçóëüòèðóþùåå çíà÷åíèå + è òèï îïðåäåëÿåòñÿ òàê êàê ïîêàçàíî äàëåå. </simpara> <simpara> - The string will evaluate as a <type>float</type> if it contains any of the - characters '.', 'e', or 'E'. Otherwise, it will evaluate as an - integer. + Ñòðîêà áóäåò ðàñïîçíàíà êàê <type>float</type>, åñëè îíà ñîäåðæèò + ëþáîé èç ñèìâîëîâ '.', 'e', èëè 'E'. Èíà÷å îíà áóäåò îïðåäåëåíà êàê + öåëîå. </simpara> <para> - The value is given by the initial portion of the string. If the - string starts with valid numeric data, this will be the value - used. Otherwise, the value will be 0 (zero). Valid numeric data - is an optional sign, followed by one or more digits (optionally - containing a decimal point), followed by an optional - exponent. The exponent is an 'e' or 'E' followed by one or more - digits. + Çíà÷åíèå îïðåäåëÿåòñÿ ïî íà÷àëüíîé ÷àñòè ñòðîêè. Åñëè ñòðîêà + íà÷èíàåòñÿ ñ âåðíîãî ÷èñëîâîãî çíà÷åíèÿ, áóäåò èñïîëüçîâàíî ýòî + çíà÷åíèå. Èíà÷å çíà÷åíèåì áóäåò 0 (íîëü). Âåðíîå ÷èñëîâîå çíà÷åíèå + - ýòî îäíà èëè áîëåå öèôð (ìîãóùèõ ñîäåðæàòü äåñÿòè÷íóþ òî÷êó), + ïî æåëàíèþ ïðåäâàðåííûõ çíàêîì, ñ ïîñëåäóþùèì íåîáÿçàòåëüíûì + ïîêàçàòåëåì ñòåïåíè. Ïîêàçàòåëü ñòåïåíè - ýòî 'e' èëè 'E' ñ + ïîñëåäóþùèìè îäíîé èëè áîëåå öèôðàìè. </para> <informalexample> <programlisting role="php"> <![CDATA[ -$foo = 1 + "10.5"; // $foo is float (11.5) -$foo = 1 + "-1.3e3"; // $foo is float (-1299) -$foo = 1 + "bob-1.3e3"; // $foo is integer (1) -$foo = 1 + "bob3"; // $foo is integer (1) -$foo = 1 + "10 Small Pigs"; // $foo is integer (11) -$foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2) -$foo = "10.0 pigs " + 1; // $foo is float (11) -$foo = "10.0 pigs " + 1.0; // $foo is float (11) +$foo = 1 + "10.5"; // $foo ýòî float (11.5) +$foo = 1 + "-1.3e3"; // $foo ýòî float (-1299) +$foo = 1 + "bob-1.3e3"; // $foo ýòî integer (1) +$foo = 1 + "bob3"; // $foo ýòî integer (1) +$foo = 1 + "10 Small Pigs"; // $foo ýòî integer (11) +$foo = 4 + "10.2 Little Piggies"; // $foo ýòî float (14.2) +$foo = "10.0 pigs " + 1; // $foo ýòî float (11) +$foo = "10.0 pigs " + 1.0; // $foo ýòî float (11) ]]> </programlisting> </informalexample> <simpara> - For more information on this conversion, see the Unix manual page - for strtod(3). + Áîëåå ïîäðîáíóþ èíôîðìàöèþ îá ýòîé êîíâåðòàöèè ñìîòðèòå â + äîêóìåíòàöèè ïî Unix â ðàçäåëå î strtod(3). </simpara> <para> - If you would like to test any of the examples in this section, - you can cut and paste the examples and insert the following line - to see for yourself what's going on: + Åñëè âû õîòèòå ïðîòåñòèðîâàòü ëþáîé èç ïðèìåðîâ ýòîãî ðàçäåëà, + âû ìîæåòå ñêîïèðîâàòü è âñòàâèòü åãî è ñëåäóþùóþ ñòðîêó, ÷òîáû + óâèäåòü, ÷òî ïðîèñõîäèò: <informalexample> <programlisting role="php"> <![CDATA[ -echo "\$foo==$foo; type is " . gettype ($foo) . "<br />\n"; +echo "\$foo==$foo; òèï: " . gettype ($foo) . "<br />\n"; ]]> </programlisting> </informalexample> </para> <para> - Do not expect to get the code of one character by converting it - to integer (as you would do in C for example). Use the functions - <function>ord</function> and <function>chr</function> to convert - between charcodes and characters. + Íå îæèäàéòå ïîëó÷èòü êîä ñèìâîëà, êîíâåðòèðîâàâ åãî â öåëîå (êàê + âû ìîãëè áû ñäåëàòü, íàïðèìåð, â C). Äëÿ êîíâåðòàöèè ñèìâîëîâ â + èõ êîäû è îáðàòíî èñïîëüçóéòå ôóíêöèè <function>ord</function> + è <function>chr</function>. </para> </sect2> </sect1><!-- end string --> <sect1 id="language.types.array"> - <title>Arrays</title> + <title>Ìàññèâû</title> <para> An array in PHP is actually an ordered map. A map is a type that
Index: phpdoc-ru/language/types.xml diff -u phpdoc-ru/language/types.xml:1.2 phpdoc-ru/language/types.xml:1.3 --- phpdoc-ru/language/types.xml:1.2 Tue Jan 28 07:27:04 2003 +++ phpdoc-ru/language/types.xml Mon Mar 3 06:01:40 2003 @@ -1,20 +1,21 @@ <?xml version="1.0" encoding="windows-1251"?> -<!-- EN-Revision: 1.98 Maintainer: Kai Status: in-progress --> -<!-- $Revision: 1.2 $ --> +<!-- EN-Revision: 1.98 Maintainer: Kai Status: not yet ready --> +<!-- $Revision: 1.3 $ --> <chapter id="language.types"> <title>Òèïû</title> <!-- - Çàìå÷àíèå: Ïîñëåäíåå èçìåíåíèå çàìåòêè: 2003-09-01 - resource ïåðåâåë êàê èñòî÷íèê + Çàìå÷àíèå: Ïîñëåäíåå èçìåíåíèå çàìåòêè: 2003-03-03 + resource - ðåñóðñ control structure = óïðàâëÿþùàÿ êîíñòðóêöèÿ language.types.string.conversion = Êîíâåðòàöèÿ ñòðîê â ÷èñëà Arbitrary Precision Mathematics Functions=ìàòåìàòè÷åñêèå ôóêöèè ïðîèçâîëüíîé òî÷íîñòè String conversion to numbers = Êîíâåðòàöèÿ ñòðîê â ÷èñëà language.types.integer.casting = - è äðóãèå ññûëêè - óòî÷íèòü - heredoc-ñèíòàêñèñ - êàê ïåðåâåñòè? + è äðóãèå ññûëêè + heredoc-ñèíòàêñèñ Escaped characters + language.operators.string --> <sect1 id="language.types.intro"> @@ -79,7 +80,7 @@ <listitem> <simpara> - <link linkend="language.types.resource">èñòî÷íèê</link> + <link linkend="language.types.resource">ðåñóðñ</link> </simpara> </listitem> @@ -744,48 +745,47 @@ <title>Heredoc</title> <simpara> Äðóãîé ñïîñîá îïðåäåëåíèÿ ñòðîê - ýòî èñïîëüçîâàíèå - heredoc-ñèíòàêñèñà ("<<<"). One should provide an identifier after - <literal><<<</literal>, then the string, and then the - same identifier to close the quotation. + heredoc-ñèíòàêñèñà ("<<<"). Ïîñëå + <literal><<<</literal> íåîáõîäèìî óêàçàòü èäåíòèôèêàòîð, + çàòåì èäåò ñòðîêà, à ïîòîì ýòîò æå èäåíòèôèêàòîð, çàêðûâàþùèé âñòàâêó. </simpara> <simpara> - The closing identifier <emphasis>must</emphasis> begin in the - first column of the line. Also, the identifier used must follow - the same naming rules as any other label in PHP: it must contain - only alphanumeric characters and underscores, and must start with - a non-digit character or underscore. + Çàêðûâàþùèé èäåíòèôèêòîð <emphasis>äîëæåí</emphasis> íà÷èíàòüñÿ â + ïåðâîì ñòîëáöå ñòðîêè. Êðîìå òîãî, èäåíòèôèêàòîð äîëæåí + ñîîòâåòñòâîâàòü òåì æå ïðàâèëàì èìåíîâàíèÿ, ÷òî è âñå îñòàëüíûå + ìåòêè â PHP: ñîäåðæàòü òîëüêî áóêâåííî-öèôðîâûå ñèìâîëû è çíàê + ïîä÷åðêèâàíèÿ, è äîëæåí íà÷èíàòüñÿ ñ íåöèôðû èëè çíàêà ïîä÷åðêèâàíèÿ. </simpara> <warning> <simpara> - It is very important to note that the line with the closing - identifier contains no other characters, except - <emphasis>possibly</emphasis> a semicolon (<literal>;</literal>). - That means especially that the identifier - <emphasis>may not be indented</emphasis>, and there - may not be any spaces or tabs after or before the semicolon. + Âàæíî îòìåòèòü, ÷òî ñòðîêà ñ çàêðûâàþùèì èäåíòèôèêàòîðîì íå ñîäåðæèò + äðóãèõ ñèìâîëîâ, çà èñêëþ÷åíèåì, <emphasis>âîçìîæíî</emphasis>, + òî÷êè ñ çàïÿòîé (<literal>;</literal>). Ýòî îçíà÷àåò, ÷òî èäåíòèôèêàòîð + <emphasis>íå äîëæåí ââîäèòüñÿ ñ îòñòóïîì</emphasis> è ÷òî íå ìîæåò + áûòü íèêàêèõ ïðîáåëîâ èëè çíàêîâ òàáóëÿöèè äî èëè ïîñëå òî÷êè ñ çàïÿòîé. </simpara> </warning> <para> - Heredoc text behaves just like a double-quoted string, without - the double-quotes. This means that you do not need to escape quotes - in your here docs, but you can still use the escape codes listed - above. Variables are expanded, but the same care must be taken - when expressing complex variables inside a here doc as with - strings. + Heredoc-òåêñò âåä¸ò ñåáÿ òàê æå, êàê è ñòðîêà â äâîéíûõ êàâû÷êàõ, + íî áåç íèõ. Ýòî îçíà÷àåò, ÷òî âàì íåò íåîáõîäèìîñòè ìíåìîíèçèðîâàòü + êàâû÷êè â heredoc, íî âû ïî-ïðåæíåìó ìîæåòå èñïîëüçîâàòü + âûøåïåðå÷èñëåííûå êîäû-ìíåìîíèêè. Ïåðåìåííûå îáðàáàòûâàþòñÿ, íî + ñ ïðèìåíåíèåì ñëîæíûõ ïåðåìåííûõ âíóòðè heredoc íóæíî áûòü òàêæå + âíèìàòåëüíûì, êàê è ïðè ðàáîòå ñî ñòðîêàìè. <example> - <title>Heredoc string quoting example</title> + <title>Ïðèìåð îïðåäåëåíèÿ heredoc-ñòðîêè</title> <programlisting role="php"> <![CDATA[ <?php $str = <<<EOD -Example of string -spanning multiple lines -using heredoc syntax. +Ïðèìåð ñòðîêè, +îõâàòûâàþùåé íåñêîëüêî ñòðî÷åê +ñ èñïîëüçîâàíèåì heredoc-ñèíòàêñèñà. EOD; -/* More complex example, with variables. */ +/* Áîëåå ñëîæíûé ïðèìåð ñ ïåðåìåííûìè. */ class foo { var $foo; @@ -799,12 +799,12 @@ } $foo = new foo(); -$name = 'MyName'; +$name = 'ÌîåÈìÿ'; echo <<<EOT -My name is "$name". I am printing some $foo->foo. -Now, I am printing some {$foo->bar[1]}. -This should print a capital 'A': \x41 +Ìåíÿ çîâóò "$name". ß ïå÷àòàþ $foo->foo. +Òåïåðü ÿ âûâîæó {$foo->bar[1]}. +Ýòî äîëæíî âûâåñòè çàãëàâíóþ áóêâó 'A': \x41 EOT; ?> ]]> @@ -814,56 +814,53 @@ <note> <para> - Heredoc support was added in PHP 4. + Ïîääåðæêà heredoc áûëà äîáàâëåíà â PHP 4. </para> </note> </sect3> <sect3 id="language.types.string.parsing"> - <title>Variable parsing</title> + <title>Îáðàáîòêà ïåðåìåííûõ</title> <simpara> - When a string is specified in double quotes or with - heredoc, variables are parsed within it. + Åñëè ñòðîêà îïðåäåëÿåòñÿ â äâîéíûõ êàâû÷êàõ, ëèáî ïðè ïîìîùè + heredoc, ïåðåìåííûå âíóòðè íåå îáðàáàòûâàþòñÿ. </simpara> <simpara> - There are two types of syntax, a - <link linkend="language.types.string.parsing.simple">simple</link> - one and a - <link linkend="language.types.string.parsing.complex">complex</link> - one. - The simple syntax is the most common and convenient, it provides a way - to parse a variable, an array value, or an object property. + Ñóùåñòâóåò äâà òèïà ñèíòàêñèñà - + <link linkend="language.types.string.parsing.simple">ïðîñòîé</link> è + <link linkend="language.types.string.parsing.complex">ñëîæíûé</link>. + Ïðîñòîé ñèíòàêñèñ áîëåå ëåãîê è óäîáåí, îí äàåò âîçìîæíîñòü + îáðàáîòêè ïåðåìåííîé, çíà÷åíèÿ ìàññèâà èëè ñâîéñòâà îáúåêòà. </simpara> <simpara> - The complex syntax was introduced in PHP 4, and can be recognised - by the curly braces surrounding the expression. + Ñëîæíûé ñèíòàêñèñ áûë ââåäåí â PHP 4 è ìîæåò áûòü ðàñïîçíàí + ïî ôèãóðíûì ñêîáêàì, îêðóæàþùèõ âûðàæåíèå. </simpara> <sect4 id="language.types.string.parsing.simple"> - <title>Simple syntax</title> + <title>Ïðîñòîé ñèíòàêñèñ</title> <simpara> - If a dollar sign (<literal>$</literal>) is encountered, the - parser will greedily take as much tokens as possible to form a - valid variable name. Enclose the variable name in curly - braces if you want to explicitly specify the end of the name. + Åñëè èíòåðïðåòàòîð âñòðå÷àåò çíàê äîëëàðà (<literal>$</literal>), îí + çàõâàòûâàåò ñòîëüêî ñèìâîëîâ, ñêîëüêî âîçìîæíî, ÷òîáû ñôîðìèðîâàòü + ïðàâèëüíîå èìÿ ïåðåìåííîé. Åñëè âû õîòèòå òî÷íî îïðåäåëèòü êîíåö èìåíè, + çàêëþ÷àéòå èìÿ ïåðåìåííîé â ôèãóðíûå ñêîáêè. </simpara> <informalexample> <programlisting role="php"> <![CDATA[ $beer = 'Heineken'; -echo "$beer's taste is great"; // works, "'" is an invalid character for varnames -echo "He drank some $beers"; // won't work, 's' is a valid character for varnames -echo "He drank some ${beer}s"; // works +echo "$beer's taste is great"; // ðàáîòàåò, "'" ýòî íåâåðíûé ñèìâîë äëÿ èìåíè ïåðåìåííîé +echo "He drank some $beers"; // íå ðàáîòàåò, 's' ýòî âåðíûé ñèìâîë äëÿ èìåíè ïåðåìåííîé +echo "He drank some ${beer}s"; // ðàáîòàåò ]]> </programlisting> </informalexample> <simpara> - Similarly, you can also have an array index or an object - property parsed. With array indices, the closing square bracket - (<literal>]</literal>) marks the end of the index. For - object properties the same rules apply as to simple variables, - though with object properties there doesn't exist a trick like - the one with variables. + Òî÷íî òàêæå ìîãóò áûòü îáðàáîòàíû ýëåìåíò ìàññèâà èëè ñâîéñòâî + îáúåêòà.  ýëåìåíòàõ ìàññèâà çàêðûâàþùàÿ êâàäðàòíàÿ ñêîáêà + (<literal>]</literal>) îáîçíà÷àåò êîíåö îïðåäåëåíèÿ ýëåìåíòà. + Äëÿ ñâîéñòâ îáúåêòà ïðèìåíÿþòñÿ òå æå ïðàâèëà, ÷òî è äëÿ ïðîñòûõ + ïåðåìåííûõ, õîòÿ ñ íèìè íåâîçìîæåí òðþê, êàê ñ ïåðåìåííûìè. <!-- XXX isn't &true; :(, this would be the trick Also, the same trick with curly-braces works if you @@ -876,12 +873,12 @@ <![CDATA[ $fruits = array('strawberry' => 'red', 'banana' => 'yellow'); -// note that this works differently outside string-quotes +// Çàìåòüòå, ÷òî âíå êàâû÷åê ýòà êîíñòðóêöèÿ ðàáîòàåò ïî-äðóãîìó echo "A banana is $fruits[banana]."; echo "This square is $square->width meters broad."; -// Won't work. For a solution, see the complex syntax. +// Íå ðàáîòàåò. Äëÿ ðåøåíèÿ ñì. ñëîæíûé ñèíòàêñèñ. echo "This square is $square->width00 centimeters broad."; ]]> @@ -894,41 +891,42 @@ </programlisting> </informalexample> <simpara> - For anything more complex, you should use the complex syntax. + Äëÿ ÷åãî-ëèáî áîëåå ñëîæíîãî âû äîëæíû èñïîëüçîâàòü ñëîæíûé ñèíòàêñèñ. </simpara> </sect4> <sect4 id="language.types.string.parsing.complex"> - <title>Complex (curly) syntax</title> + <title>Ñëîæíûé (ôèãóðíûé) ñèíòàêñèñ</title> <simpara> - This isn't called complex because the syntax is complex, - but because you can include complex expressions this way. + Îí íàçûâàåòñÿ ñëîæíûì íå ïîòîìó, ÷òî òðóäåí â ïîíèìàíèè, + à ïîòîìó ÷òî ïîçâîëÿåò èñïîëüçîâàòü ñëîæíûå âûðàæåíèÿ. </simpara> <simpara> - In fact, you can include any value that is in the namespace - in strings with this syntax. You simply write the expression - the same way as you would outside the string, and then include - it in { and }. Since you can't escape '{', this syntax will - only be recognised when the $ is immediately following the {. - (Use "{\$" or "\{$" to get a literal "{$"). - Some examples to make it clear: + Ôàêòè÷åñêè, âû ìîæåòå âêëþ÷èòü ëþáîå çíà÷åíèå, íàõîäÿùååñÿ â + ïðîñòðàíñòâå èìåíè â ñòðîêå ñ ýòèì ñèíòàêñèñîì. Âû ïðîñòî + çàïèñûâàåòå âûðàæåíèå òàêèì æå îáðàçîì, êàê è âíå ñòðîêè, à + çàòåì çàêëþ÷àåòå åãî â { è }. Ïîñêîëüêó âû íå ìîæåòå çàìåíèòü + ìíåìîíèêîé '{', ýòîò ñèíòàêñèñ áóäåò ðàñïîçíàâàòüñÿ òîëüêî + êîãäà $ ñëåäóåò íåïîñðåäñòâåííî çà {. (Èñïîëüçóéòå "{\$" èëè + "\{$" ÷òîáû îòîáðàçèòü "{$"). + Íåñêîëüêî ïîÿñíÿþùèõ ïðèìåðîâ: </simpara> <informalexample> <programlisting role="php"> <![CDATA[ $great = 'fantastic'; -echo "This is { $great}"; // won't work, outputs: This is { fantastic} -echo "This is {$great}"; // works, outputs: This is fantastic -echo "This square is {$square->width}00 centimeters broad."; -echo "This works: {$arr[4][3]}"; - -// This is wrong for the same reason -// as $foo[bar] is wrong outside a string. -echo "This is wrong: {$arr[foo][3]}"; - -echo "You should do it this way: {$arr['foo'][3]}"; -echo "You can even write {$obj->values[3]->name}"; -echo "This is the value of the var named $name: {${$name}}"; +echo "This is { $great}"; // íå áóäåò ðàáîòàòü, âûâåäåò: This is { fantastic} +echo "This is {$great}"; // ðàáîòàåò, âûâåäåò: This is fantastic +echo "Ýòîò êâàäðàò øèðèíîé {$square->width}00 ñàíòèìåòðîâ."; +echo "Ýòî ðàáîòàåò: {$arr[4][3]}"; + +// Ýòî íåâåðíî ïî òîé æå ïðè÷èíå, +// ÷òî è $foo[bar] íåâåðíî âíå ñòðîêè. +echo "Ýòî íåïðàâèëüíî: {$arr[foo][3]}"; + +echo "Ñëåäóåò äåëàòü ýòî òàê: {$arr['foo'][3]}"; +echo "Âû ìîæåòå äàæå çàïèñàòü {$obj->values[3]->name}"; +echo "Ýòî çíà÷åíèå ïåðåìåííîé ïî èìåíè $name: {${$name}}"; ]]> <!-- maybe it's better to leave this out?? // this works, but i disencourage its use, since this is NOT @@ -942,31 +940,32 @@ </sect3> <sect3 id="language.types.string.substr"> - <title>String access by character</title> + <title>Äîñòóï ê ñèìâîëó â ñòðîêå</title> <para> - Characters within strings may be accessed by specifying the - zero-based offset of the desired character after the string - in curly braces. + Ñèìâîëû â ñòðîêàõ ìîæíî èñïîëüçîâàòü, îïðåäåëèâ èõ ñìåùåíèå + îòíîñèòåëüíî íà÷àëà ñòðîêè, íà÷èíàÿ ñ íóëÿ, â ôèãóðíûõ + ñêîáêàõ ïîñëå ñòðîêè. </para> <note> <simpara> - For backwards compatibility, you can still use array-braces - for the same purpose. However, this syntax is deprecated as - of PHP 4. + Äëÿ îáåñïå÷åíèÿ îáðàòíîé ñîâìåñòèìîñòè, âû ïî-ïðåæíåìó èìååòå + âîçìîæíîñòü èñïîëüçîâàòü â òåõ æå öåëÿõ ñêîáêè ìàññèâà. + Îäíàêî, íà÷èíàÿ ñ PHP 4, ýòîò ñèíòàêñèñ íåæåëàòåëåí ê + èñïîëüçîâàíèþ. </simpara> </note> <para> <example> - <title>Some string examples</title> + <title>Íåñêîëüêî ïðèìåðîâ ñòðîê</title> <programlisting role="php"> <![CDATA[ <?php -// Get the first character of a string -$str = 'This is a test.'; +// Ïîëó÷åíèå ïåðâîãî ñèìâîëà ñòðîêè +$str = 'Ýòî òåñò.'; $first = $str{0}; -// Get the last character of a string. -$str = 'This is still a test.'; +// Ïîëó÷åíèå ïîñëåäíåãî ñèìâîëà ñòðîêè +$str = 'Ýòî âñå åùå òåñò.'; $last = $str{strlen($str)-1}; ?> ]]> @@ -978,160 +977,160 @@ </sect2><!-- end syntax --> <sect2 id="language.types.string.useful-funcs"> - <title>Useful functions and operators</title> + <title>Ïîëåçíûå ôóíêöèè è îïåðàòîðû</title> <para> - Strings may be concatenated using the '.' (dot) operator. Note - that the '+' (addition) operator will not work for this. Please - see <link linkend="language.operators.string">String - operators</link> for more information. + Ñòðîêè ìîãóò áûòü îáúåäèíåíû ïðè ïîìîùè îïåðàòîðà '.' (òî÷êà). + Îáðàòèòå âíèìàíèå, îïåðàòîð ñëîæåíèÿ '+' çäåñü íå ðàáîòàåò. + Äîïîëíèòåëüíóþ èíôîðìàöèþ ñìîòðèòå â ðàçäåëå <link + linkend="language.operators.string">Ñòðîêîâûå îïåðàòîðû</link>. </para> <para> - There are a lot of useful functions for string modification. + Äëÿ ìîäèôèêàöèè ñòðîê ñóùåñòâóåò ìíîæåñòâî ïîëåçíûõ ôóíêöèé. </para> <simpara> - See the <link linkend="ref.strings">string functions section</link> - for general functions, the regular expression functions for - advanced find&replacing (in two tastes: - <link linkend="ref.pcre">Perl</link> and - <link linkend="ref.regex">POSIX extended</link>). + Îñíîâíûå ôóíêöèè îïèñàíû â ðàçäåëå + <link linkend="ref.strings">ñòðîêîâûõ ôóíêöèé</link>, ôóíêöèè + ðåãóëÿðíûõ âûðàæåíèé äëÿ ðàñøèðåííîãî ïîèñêà è çàìåíû (â äâóõ ÷àñòÿõ: + <link linkend="ref.pcre">Perl</link> è <link + linkend="ref.regex">POSIX ðàñøèðåííûé</link>). </simpara> <simpara> - There are also <link linkend="ref.url">functions for URL-strings</link>, - and functions to encrypt/decrypt strings - (<link linkend="ref.mcrypt">mcrypt</link> and - <link linkend="ref.mhash">mhash</link>). + Òàêæå ñóùåñòâóþò <link linkend="ref.url">ôóíêöèè äëÿ URL-ñòðîê</link>, + è ôóíêöèè äëÿ øèôðîâàíèÿ/äåøèôðîâàíèÿ ñòðîê (<link + linkend="ref.mcrypt">mcrypt</link> è <link + linkend="ref.mhash">mhash</link>). </simpara> <simpara> - Finally, if you still didn't find what you're looking for, - see also the <link linkend="ref.ctype">character type functions</link>. + Íàêîíåö, åñëè âû âñå åùå íå íàøëè, ÷òî èñêàëè, ñìîòðèòå òàêæå + <link linkend="ref.ctype">ôóíêöèè äëÿ ñèìâîëüíîãî òèïà</link>. </simpara> </sect2> <sect2 id="language.types.string.casting"> - <title>Converting to string</title> + <title>Êîíâåðòàöèÿ â ñòðîêó</title> <para> - You can convert a value to a string using the <literal>(string)</literal> - cast, or the <function>strval</function> function. String conversion - is automatically done in the scope of an expression for you where a - string is needed. This happens when you use the <function>echo</function> - or <function>print</function> functions, or when you compare a variable - value to a string. + Âû ìîæåòå êîíâåðòèðîâàòü çíà÷åíèå â ñòðîêó, èñïîëüçóÿ ïðèâåäåíèå + <literal>(string)</literal>, ëèáî ôóíêöèþ <function>strval</function>. +  âûðàæåíèÿõ, ãäå íåîáõîäèìà ñòðîêà, êîíâåðòàöèÿ ïðîèñõîäèò àâòîìàòè÷åñêè. + Ýòî ïðîèñõîäèò, êîãäà âû èñïîëüçóåòå ôóíêöèè <function>echo</function> + èëè <function>print</function>, ëèáî êîãäà âû ñðàâíèâàåòå çíà÷åíèå + ïåðåìåííîé ñî ñòðîêîé. </para> <para> - A boolean &true; value is converted to the string <literal>"1"</literal>, - the &false; value is represented as <literal>""</literal> (empty string). - This way you can convert back and forth between boolean and string values. + Ëîãè÷åñêîå çíà÷åíèå &true; êîíâåðòèðóåòñÿ â ñòðîêó <literal>"1"</literal>, + à çíà÷åíèå &false; ïðåäñòàâëÿåòñÿ êàê <literal>""</literal> (ïóñòàÿ ñòðîêà). + Ýòèì ñïîñîáîì âû ìîæåòå êîíâåðòèðîâàòü çíà÷åíèÿ â îáå ñòîðîíû èç áóëåâà + òèïà â ñòðîêîâûé è íàîáîðîò. </para> <para> - An integer or a floating point number is converted to a string - representing the number with its digits (includig the exponent part - for floating point numbers). + Öåëîå èëè ÷èñëî ñ ïëàâàþùåé òî÷êîé êîíâåðòèðóåòñÿ â ñòðîêó, ïðåäñòàâëåííóþ + ÷èñëîì, ñîñòîÿùèì èç åãî öèôð (âêëþ÷àÿ ïîêàçàëòåëü ñòåïåíè äëÿ ÷èñåë ñ + ïëàâàþùåé òî÷êîé). </para> <para> - Arrays are always converted to the string <literal>"Array"</literal>, - so you cannot dump out the contents of an array with <function>echo</function> - or <function>print</function> to see what is inside them. See the information - below for more tips. + Ìàññèâû âñåãäà êîíâåðòèðóþòñÿ â ñòðîêó <literal>"Array"</literal>, + òàê ÷òî âû íå ìîæåòå îòîáðàçèòü ñîäåðæèìîå ìàññèâà, èñïîëüçóÿ + <function>echo</function> èëè <function>print</function>, ÷òîáû óçíàòü, + ÷òî îí ñîäåðæèò. Äîïîëíèòåëüíûå ñîâåòû âû ìîæåòå íàéòè íèæå. </para> <para> - Objects are always converted to the string <literal>"Object"</literal>. - If you would like to print out the member variable values of an object - for debugging reasons, read the paragraphs below. If you would - like to find out the class name of which an object is an instance of, - use <function>get_class</function>. + Îáúåêòû âñåãäà êîíâåðòèðóþòñÿ â ñòðîêó <literal>"Object"</literal>. + Åñëè âû õîòèòå âûâåñòè çíà÷åíèå ïåðåìåííîé-÷ëåíà îáúåêòà ïî ïðè÷èíå + îòëàäêè, ïðî÷òèòå ñëåäóþùèå àáçàöû. Åñëè âû õîòèòå ïîëó÷èòü èìÿ êëàññà + òðåáóåìîãî îáúåêòà, èñïîëüçóéòå ôóíêöèþ <function>get_class</function>. </para> <para> - Resources are always converted to strings with the structure - <literal>"Resource id #1"</literal> where <literal>1</literal> is - the unique number of the resource assigned by PHP during runtime. - If you would like to get the type of the resource, use + Ðåñóðñû âñåãäà êîíâåðòèðóþòñÿ â ñòðîêè ñî ñòðóêòóðîé + <literal>"Resource id #1"</literal>, ãäå <literal>1</literal> - ýòî + óíèêàëüíûé íîìåð ðåñóðñà, ïðèñâîåííûé åìó PHP âî âðåìÿ âûïîëíåíèÿ. + Åñëè âû õîòèòå ïîëó÷èòü òèï ðåñóðñà, èñïîëüçóéòå ôóíêöèþ <function>get_resource_type</function>. </para> <para> - &null; is always converted to an empty string. + &null; âñåãäà êîíâåðòèðóåòñÿ â ïóñòóþ ñòðîêó. </para> <para> - As you can see above, printing out the arrays, objects or resources does not - provide you any useful information about the values themselfs. Look at the - functions <function>print_r</function> and <function>var_dump</function> - for better ways to print out values for debugging. + Êàê âû ìîãëè âèäåòü âûøå, âûâîä ìàññèâîâ, îáúåêòîâ èëè ðåñóðñîâ íå + ïðåäîñòàâëÿåò âàì íèêàêîé ïîëåçíîé èíôîðìàöèè î ñàìèõ çíà÷åíèÿõ. Áîëåå + ïîäõîäÿùèé ñïîñîá âûâîäà çíà÷åíèé äëÿ îòëàäêè - èñïîëüçîâàòü ôóíêöèè + <function>print_r</function> è <function>var_dump</function>. </para> <para> - You can also convert PHP values to strings to store them permanently. This - method is called serialization, and can be done with the function - <function>serialize</function>. You can also serialize PHP values to - XML structures, if you have <link linkend="ref.wddx">WDDX</link> support - in your PHP setup. + Âû òàêæå ìîæåòå êîíâåðòèðîâàòü çíà÷åíèÿ PHP â ñòðîêè äëÿ ïîñòîÿííîãî + õðàíåíèÿ. Ýòîò ìåòîä íàçûâàåòñÿ ñåðèàëèçàöèåé è ìîæåò áûòü âûïîëíåí + ïðè ïîìîùè ôóíêöèè <function>serialize</function>. Êðîìå òîãî, åñëè â + âàøåé óñòàíîâêå PHP åñòü ïîääåðæêà <link linkend="ref.wddx">WDDX</link>, + âû ìîæåòå ñåðèàëèçîâàòü çíà÷åíèÿ PHP â ñòðóêòóðû XML. </para> </sect2> <sect2 id="language.types.string.conversion"> - <title>String conversion to numbers</title> + <title>Êîíâåðòàöèÿ ñòðîê â ÷èñëà</title> <simpara> - When a string is evaluated as a numeric value, the resulting - value and type are determined as follows. + Åñëè ñòðîêà ðàñïîçíàåòñÿ êàê ÷èñëîâîå çíà÷åíèå, ðåçóëüòèðóþùåå çíà÷åíèå + è òèï îïðåäåëÿåòñÿ òàê êàê ïîêàçàíî äàëåå. </simpara> <simpara> - The string will evaluate as a <type>float</type> if it contains any of the - characters '.', 'e', or 'E'. Otherwise, it will evaluate as an - integer. + Ñòðîêà áóäåò ðàñïîçíàíà êàê <type>float</type>, åñëè îíà ñîäåðæèò + ëþáîé èç ñèìâîëîâ '.', 'e', èëè 'E'. Èíà÷å îíà áóäåò îïðåäåëåíà êàê + öåëîå. </simpara> <para> - The value is given by the initial portion of the string. If the - string starts with valid numeric data, this will be the value - used. Otherwise, the value will be 0 (zero). Valid numeric data - is an optional sign, followed by one or more digits (optionally - containing a decimal point), followed by an optional - exponent. The exponent is an 'e' or 'E' followed by one or more - digits. + Çíà÷åíèå îïðåäåëÿåòñÿ ïî íà÷àëüíîé ÷àñòè ñòðîêè. Åñëè ñòðîêà + íà÷èíàåòñÿ ñ âåðíîãî ÷èñëîâîãî çíà÷åíèÿ, áóäåò èñïîëüçîâàíî ýòî + çíà÷åíèå. Èíà÷å çíà÷åíèåì áóäåò 0 (íîëü). Âåðíîå ÷èñëîâîå çíà÷åíèå + - ýòî îäíà èëè áîëåå öèôð (ìîãóùèõ ñîäåðæàòü äåñÿòè÷íóþ òî÷êó), + ïî æåëàíèþ ïðåäâàðåííûõ çíàêîì, ñ ïîñëåäóþùèì íåîáÿçàòåëüíûì + ïîêàçàòåëåì ñòåïåíè. Ïîêàçàòåëü ñòåïåíè - ýòî 'e' èëè 'E' ñ + ïîñëåäóþùèìè îäíîé èëè áîëåå öèôðàìè. </para> <informalexample> <programlisting role="php"> <![CDATA[ -$foo = 1 + "10.5"; // $foo is float (11.5) -$foo = 1 + "-1.3e3"; // $foo is float (-1299) -$foo = 1 + "bob-1.3e3"; // $foo is integer (1) -$foo = 1 + "bob3"; // $foo is integer (1) -$foo = 1 + "10 Small Pigs"; // $foo is integer (11) -$foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2) -$foo = "10.0 pigs " + 1; // $foo is float (11) -$foo = "10.0 pigs " + 1.0; // $foo is float (11) +$foo = 1 + "10.5"; // $foo ýòî float (11.5) +$foo = 1 + "-1.3e3"; // $foo ýòî float (-1299) +$foo = 1 + "bob-1.3e3"; // $foo ýòî integer (1) +$foo = 1 + "bob3"; // $foo ýòî integer (1) +$foo = 1 + "10 Small Pigs"; // $foo ýòî integer (11) +$foo = 4 + "10.2 Little Piggies"; // $foo ýòî float (14.2) +$foo = "10.0 pigs " + 1; // $foo ýòî float (11) +$foo = "10.0 pigs " + 1.0; // $foo ýòî float (11) ]]> </programlisting> </informalexample> <simpara> - For more information on this conversion, see the Unix manual page - for strtod(3). + Áîëåå ïîäðîáíóþ èíôîðìàöèþ îá ýòîé êîíâåðòàöèè ñìîòðèòå â + äîêóìåíòàöèè ïî Unix â ðàçäåëå î strtod(3). </simpara> <para> - If you would like to test any of the examples in this section, - you can cut and paste the examples and insert the following line - to see for yourself what's going on: + Åñëè âû õîòèòå ïðîòåñòèðîâàòü ëþáîé èç ïðèìåðîâ ýòîãî ðàçäåëà, + âû ìîæåòå ñêîïèðîâàòü è âñòàâèòü åãî è ñëåäóþùóþ ñòðîêó, ÷òîáû + óâèäåòü, ÷òî ïðîèñõîäèò: <informalexample> <programlisting role="php"> <![CDATA[ -echo "\$foo==$foo; type is " . gettype ($foo) . "<br />\n"; +echo "\$foo==$foo; òèï: " . gettype ($foo) . "<br />\n"; ]]> </programlisting> </informalexample> </para> <para> - Do not expect to get the code of one character by converting it - to integer (as you would do in C for example). Use the functions - <function>ord</function> and <function>chr</function> to convert - between charcodes and characters. + Íå îæèäàéòå ïîëó÷èòü êîä ñèìâîëà, êîíâåðòèðîâàâ åãî â öåëîå (êàê + âû ìîãëè áû ñäåëàòü, íàïðèìåð, â C). Äëÿ êîíâåðòàöèè ñèìâîëîâ â + èõ êîäû è îáðàòíî èñïîëüçóéòå ôóíêöèè <function>ord</function> + è <function>chr</function>. </para> </sect2> </sect1><!-- end string --> <sect1 id="language.types.array"> - <title>Arrays</title> + <title>Ìàññèâû</title> <para> An array in PHP is actually an ordered map. A map is a type that