cvs: phpdoc-zh /faq using.xml
| From: | Dallas Thunder | Date: | Wed, 04 Sep 2002 03:43:27 +0000 |
| Subject: | cvs: phpdoc-zh /faq using.xml | ||
| Groups: | php.doc.zh | ||
| Request: | Send a blank email to doc-zh+get-452@lists.php.net to get a copy of this message | ||
dallas Tue Sep 3 23:43:27 2002 EDT
Modified files:
/phpdoc-zh/faq using.xml
Log:
Translation completed.
Index: phpdoc-zh/faq/using.xml diff -u phpdoc-zh/faq/using.xml:1.1 phpdoc-zh/faq/using.xml:1.2 --- phpdoc-zh/faq/using.xml:1.1 Mon Sep 2 16:29:28 2002 +++ phpdoc-zh/faq/using.xml Tue Sep 3 23:43:26 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $Author: dallas $ --> <!-- EN-Revision:1.19 Maintainer: dallas Status: ready --> <chapter id="faq.using"> @@ -7,30 +7,23 @@ <titleabbrev>ʹÓà PHP</titleabbrev> <para> - This section gathers most common errors you can - face, while writing PHP scripts. + ±¾½Ú»ã¼¯ÁËÄãÔÚд PHP ½Å±¾Ê±Åöµ½µÄ´ó¶àÊýÆÕͨ´íÎó¡£ </para> <qandaset> <qandaentry id="faq.using.anyform"> <question> <para> - I would like to write a generic PHP script that can handle data coming - from any form. How do I know which POST method variables are available? + ÎÒÏëдһ¸ö¿ÉÒÔ´¦ÀíÈÎºÎ±íµ¥À´µÄÊý¾ÝµÄͨÓà PHP ½Å±¾¡£ÎÒÔõô֪µÀÄĸö POST ·½·¨±äÁ¿¿ÉÓÃÄØ£¿ </para> </question> <answer> <para> - Make sure that the <link linkend="ini.track-vars">track_vars</link> - feature is enabled in your &php.ini; - file. Since PHP 4.0.3, this feature is always on. When - <literal>track_vars</literal> is on, it creates some - associative arrays, the most important here is: - <literal>$_POST</literal> (this used to be called - <literal>$HTTP_POST_VARS</literal> in <literal>PHP</literal> versions - prior 4.1.0). So, to write a generic - script to handle POST method variables you would - need something similar to the following: + È·±£ÔÚ &php.ini ÎļþÖ줻îÁË <link linkend="ini.track-vars">track_vars</link> ÌØÐÔ¡£×Ô´Ó PHP 4.0.3 + ¿ªÊ¼£¬´ËÌØÐÔ×ÜÊÇ´ò¿ªµÄ¡£µ± <literal>track_vars</literal> + ´ò¿ªÊ±£¬»á½¨Á¢Ò»Ð©Ïà¹ØµÄÊý×飬ÕâÀï×îÖØÒªµÄÊÇ£º<literal>$_POST</literal>£¨ÔÚ <literal>PHP</literal> 4.1.0 + ֮ǰ½Ð×ö <literal>$HTTP_POST_VARS</literal>£©¡£Òò´ËҪд³ö´¦Àí POST + ·½·¨±äÁ¿µÄͨÓýű¾ÄãÐèҪһЩÀàËÆÈçÏµķ½·¨£º <programlisting role="php"> <![CDATA[ foreach ($_POST as $var => $value) { @@ -45,17 +38,13 @@ <qandaentry id="faq.using.singlequotes"> <question> <para> - I need to convert all single-quotes (') to a backslash - followed by a single-quote. How can I do this with a - regular expression? + ÎÒÐèÒª°ÑËùÓеĵ¥ÒýºÅ£¨'£©×ª»»Îª·´Ð±ÏߺóÃæ¸ú×ŵ¥ÒýºÅ¡£ÔõÑùÓÃÕýÔò±í´ïʽ×öµ½ÄØ£¿ </para> </question> <answer> <para> - First off, take a look at the <function>addslashes</function> - function. It will do exactly what you want. You should also have - a look at the <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> - directive in your &php.ini; file. + Ê×ÏÈ¿´¿´ <function>addslashes</function> º¯Êý¡£ËüÕýÊÇ×öÕâ¼þʵġ£Í¬ÑùÒ²¿´¿´ÄãµÄ + &php.ini; ÎļþÖÐµÄ <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> Ñ¡Ïî¡£ </para> </answer> </qandaentry> @@ -63,8 +52,8 @@ <qandaentry id="faq.using.wrong-order"> <question> <para> - When I do the following, the output is printed in - the wrong order: + µ±ÎÒÕâÑù×öʱ£¬Êä³öÏÔʾµÄ´ÎÐòÊÇ´íµÄ£º + <programlisting role="php"> function myfunc($argument) { @@ -73,15 +62,13 @@ $variable = 10; echo "myfunc($variable) = " . myfunc($variable); </programlisting> - what's going on? + ÕâÊÇÔõô»ØÊ£¿ </para> </question> <answer> <para> - To be able to use the results of your function in an expression (such - as concatenating it with other strings in the example above), you need - to <emphasis>return</emphasis> the value, not <function>echo</function> - it. + ÒªÔÚÒ»¸ö±í´ïʽÖУ¨ÀýÈçÔÚÉÏÃæµÄÀý×ÓÖÐºÍÆäËü×Ö·û´®Á¬½Ó£©Ê¹Óú¯ÊýµÄ½á¹û£¬ÄãÐèÒªÓà + <emphasis>return</emphasis> ·µ»ØÕâ¸öÖµ£¬¶ø²»ÊÇ <function>echo</function> Ëü¡£ </para> </answer> </qandaentry> @@ -89,7 +76,7 @@ <qandaentry id="faq.using.newlines"> <question> <para> - Hey, what happened to my newlines? + ÏÂÃæ´úÂëÔõôûÓзֳÉÁ½ÐÐÏÔʾ£¿ <programlisting role="php"> <![CDATA[ <pre> @@ -102,18 +89,12 @@ </question> <answer> <para> - In PHP, the ending for a block of code is either "?>" or - "?>\n" (where \n means a newline). So in the example above, - the echoed sentences will be on one line, because PHP omits - the newlines after the block ending. This means that you need to - insert an extra newline after each block of PHP code to make - it print out one newline. + ÔÚ PHP ÖУ¬Ò»¶Î´úÂëµÄ½áÊø±ê¼ÇҪôÊÇ¡°?>¡±ÒªÃ´ÊÇ¡°?>\n¡±£¨\n ±íʾ»»ÐУ©¡£Òò´ËÔÚÉÏÃæµÄÀý×ÓÖУ¬Êä³öµÄ¾ä×Ó½«ÏÔʾÔÚͬһÐÐÖУ¬ÒòΪ + PHP ºöÂÔÁË´úÂë½áÊø±ê¼ÇºóÃæµÄ»»ÐС£ÕâÒâζ×ÅÈç¹ûÒªÊä³öÒ»¸ö»»Ðзû£¬ÄãÐèÒªÔÚÿ¶Î + PHP ´úÂëµÄ½áÊø±ê¼ÇºóÃæ¶à¼ÓÒ»¸ö»»ÐС£ </para> <para> - Why does PHP do this? Because when formatting normal HTML, this - usually makes your life easier because you don't want that newline, - but you'd have to create extremely long lines or otherwise make the - raw page source unreadable to achieve that effect. + PHP ΪʲôÕâô×öÄØ£¿ÒòΪÔÚ¸ñʽ»¯Õý³£µÄ HTML ʱ£¬ÕâÑùͨ³£»á¸üÈÝÒס£¼ÙÈçÊä³öÁË»»ÐжøÄã²»ÐèÒªÕâ¸ö»»ÐÐʱ£¬Äã¾Í²»µÃ²»ÓÃÒ»¸ö·Ç³£³¤µÄÐÐÀ´´ïµ½ÕâÑùµÄЧ¹û£¬»òÕßÈòúÉúµÄ HTML Ò³ÃæµÄÔ´ÎļþµÄ¸ñʽºÜÄѶÁ¡£ </para> </answer> </qandaentry> @@ -121,17 +102,13 @@ <qandaentry id="faq.using.headers-sent"> <question> <para> - I get the message 'Warning: Cannot send session cookie - headers already - sent...' or 'Cannot add header information - headers already sent...'. + Îҵõ½ÏûÏ¢¡°Warning: Cannot send session cookie - headers already + sent...¡±»òÕß¡°Cannot add header information - headers already sent...¡±¡£ </para> </question> <answer> <para> - The functions <function>header</function>, - <function>setcookie</function> and the session functions need to add - headers to the output stream. But headers can only be sent before all other - content, check if your script is sending headers after having already sent - content. + º¯Êý <function>header</function>£¬<function>setcookie</function> ºÍ session º¯ÊýÐèÒªÔÚÊä³öÁ÷ÖÐÔö¼Ó±¨Í·¡£µ«ÊDZ¨Í·Ö»ÄÜÔÚÆäËüÈκÎÊä³öÄÚÈÝ֮ǰ·¢ËÍ£¬¼ì²éÄãµÄ´úÂëÊÇ·ñÔÚÈκÎÒѾ·¢Ë͵ÄÄÚÈݺóÃæ·¢Ëͱ¨Í·¡£ </para> </answer> </qandaentry> @@ -139,15 +116,12 @@ <qandaentry id="faq.using.header"> <question> <para> - I need to access information in the request header directly. - How can I do this? + ÎÒÐèÒªÖ±½Ó·ÃÎÊÇëÇó±¨Í·ÖеÄÐÅÏ¢£¬ÔõôÄܰ쵽? </para> </question> <answer> <para> - The <function>getallheaders</function> function will do this if - you are running PHP as an Apache module. So, the following bit - of code will show you all the request headers: + Èç¹ûÄãÒÔ Apache µÄÄ£¿é·½Ê½ÔËÐÐ PHP£¬ÄÇôº¯Êý <function>getallheaders</function> ¿ÉÒÔ×öÕâ¼þÊ¡£Òò´ËÏÂÃæµÄ´úÂë¿ÉÒÔÏÔʾËùÓеÄÇëÇó±¨Í·£º <programlisting role="php"> <![CDATA[ $headers = getallheaders(); @@ -163,20 +137,15 @@ <qandaentry id="faq.using.authentication"> <question> <para> - When I try to use authentication with IIS I get 'No Input file specified'. + µ±ÎÒÓà IIS ½øÐÐ HTTP ÈÏ֤ʱµÃµ½¡°No Input file specified¡±ÏûÏ¢¡£ </para> </question> <answer> <para> - The security model of IIS is at fault here. This is a problem - common to all CGI programs running under IIS. A workaround is - to create a plain HTML file (not parsed by PHP) as the entry page - into an authenticated directory. Then use a META tag to redirect - to the PHP page, or have a link to the PHP page. PHP will - then recognize the authentication correctly. With the ISAPI - module, this is not a problem. This should not effect other - NT web servers. For more information, see: - <ulink url="&faqurl.iis;">&faqurl.iis;</ulink>. + IIS µÄ°²È«Ä£ÐÍÕâÀïÓÐ벡¡£ÕâÊÇËùÓÐ IIS ÏÂÔËÐÐµÄ CGI ³ÌÐòËù¹²ÓеÄÎÊÌâ¡£Ò»¸ö½â¾ö°ì·¨Êǽ¨Á¢Ò»¸ö´¿ + HTML Îļþ£¨²»¾¹ý PHP ½âÎö£©×÷ΪҪ½øÈëÈÏ֤Ŀ¼µÄµÇÂ¼Ò³Ãæ£¬È»ºóÓà META ±ê¼ÇÀ´Öض¨Ïòµ½ + PHP Ò³Ãæ£¬»òÕßÓÃÒ»¸öÁ¬½Óµ½ PHP Ò³Ãæ¡£È»ºó PHP ¾Í¿ÉÒÔÕýȷʶ±ðÈÏÖ¤ÐÅÏ¢ÁË¡£Èç¹ûÊÇÓà + ISAPI Ä£¿é£¬ÄÇûÓÐÕâ¸öÎÊÌâ¡£ÆäËü NT Ï嵀 web ·þÎñÆ÷²»ÊÜ´ËÓ°Ïì¡£¸ü¶àÐÅÏ¢¼û£º<ulink url="&faqurl.iis;">&faqurl.iis;</ulink>¡£ </para> </answer> </qandaentry> @@ -184,28 +153,22 @@ <qandaentry id="faq.using.netscape"> <question> <para> - My PHP script works on IE and Lynx, but on Netscape some of - my output is missing. When I do a "View Source" I see the - content in IE but not in Netscape. + ÎÒµÄ PHP ½Å±¾ÔÚ IE ºÍ Lynx ÏÂÄܹ¤×÷£¬µ«ÊÇÔÚ Netscape ÖÐÓеÄÊä³ö¶ªÊ§ÁË¡£µ±ÎÒÓᰲ鿴ԴÎļþ¡±Ê±¿ÉÒÔÔÚ + IE Öп´µ½ÄÚÈÝ£¬µ«ÊÇ Netscape Öв»ÄÜ¡£ </para> </question> <answer> <para> - Netscape is more strict regarding html tags (such as tables) then - IE. Running your html output through a html validator, such as - <ulink url="&faqurl.w3.validator;">validator.w3.org</ulink>, might - be helpful. For example, a missing </table> might cause this. + Netscape ÔÚ¹ØÓÚ html ±ê¼Ç£¨ÀýÈç table£©ÉÏ±È IE ¸üÑϸñ¡£ÓÃÒ»¸ö html ÑéÖ¤Æ÷£¬ÀýÈç + <ulink url="&faqurl.w3.validator;">validator.w3.org</ulink> À´ÑéÖ¤ÄãµÄ html + Êä³ö¿ÉÄÜ»áÓаïÖú¡£ÀýÈç©ÁË </table> ¿ÉÄܻᵼÖÂÕâÑùµÄ½á¹û¡£ </para> <para> - Also, both IE and Lynx ignore any NULs (<literal>\0</literal>) in - the HTML stream, Netscape does not. The best way to check for this is - to compile the <link linkend="features.commandline">command line</link> version of - PHP (also known as the CGI version) and run your script from the - command line. In *nix, pipe it through <literal>od -c</literal> and look - for any <literal>\0</literal> characters. If you are on Windows you need - to find an editor or some other program that lets you look at binary files. - When Netscape sees a NUL in a file it will typically not output anything - else on that line whereas both IE and Lynx will. + ͬÑù£¬IE ºÍ Lynx ¶¼ºöÂÔÁË HTML Á÷ÖеÄÈκΠNULs£¨<literal>\0</literal>£©£¬Netscape + ¾Í²»¡£×îºÃµÄ¼ì²é·½·¨ÊDZàÒë <link linkend="features.commandline">PHP µÄÃüÁîÐÐģʽ</link>°æ±¾£¨Ò²³ÆÎª + CGI °æ±¾£©²¢´ÓÃüÁîÐÐÔËÐÐÄãµÄ½Å±¾¡£ÔÚ *nix ÖУ¬ÓùܵÀ´«µÝµ½ <literal>od -c</literal> ²¢²é¿´ÈκΠ+ <literal>\0</literal> ×Ö·û¡£Èç¹ûÔÚ Windows ÏÂÄãÐèÒªÄܹ»²é¿´¶þ½øÖÆÎļþ¸ñʽµÄ±à¼Æ÷»ò³ÌÐò¡£µ± + Netscape Åöµ½ NUL ʱ¾Í²»»áÊä³öÖ®ºó¸ÃÐеÄÈκÎÄÚÈݶø IE ºÍ Lynx ¶¼»á¡£ </para> </answer> </qandaentry> @@ -213,17 +176,13 @@ <qandaentry id="faq.using.mixml"> <question> <para> - How am I supposed to mix XML and PHP? It complains - about my <?xml> tags! + ÎÒÔõÑù»ìºÏʹÓà XML ºÍ PHP£¿Ëü²»ÈÏÎÒµÄ <?xml> ±ê¼Ç£¡ </para> </question> <answer> <para> - You need to turn off the short tags by setting - <link linkend="ini.short-open-tag">short_tags</link> to 0 in your - &php.ini; file, or by using the appropriate - Apache directive. You could even use a <File> section to - do this selectively. + ÄãÐèÒªÔÚ &php.ini; ÎļþÖÐͨ¹ýÉ趨 <link linkend="ini.short-open-tag">short_tags</link> Ϊ 0 + À´¹Ø±Õ PHP µÄ¼ò¶Ì±ê¼Ç¸ñʽ£¬»òÕßͨ¹ýÏàÓ¦µÄ Apache Ñ¡Ïî¡£ÄãÉõÖÁÓ¦¸ÃÓà <File> ¶ÎÂäÀ´Ñ¡ÔñÐÔµÄÕâÑù×ö¡£ </para> </answer> </qandaentry> @@ -231,19 +190,14 @@ <qandaentry id="faq.using.editor"> <question> <para> - How can I use PHP with FrontPage or some other HTML editor - that insists on moving my code around? + ÔõÑùÓà FrontPage »òÕ߯äËü·ÇÒª°ÑÎҵĴúÂëÒÆÀ´ÒÆÈ¥µÄ HTML ±à¼Æ÷À´±à¼ PHP£¿ </para> </question> <answer> <para> - One of the easiest things to do is to enable using ASP tags in your - PHP code. This allows you to use the ASP-style <% and %> code - delimiters. Some of the popular HTML editors handle those more - intelligently (for now). To enable the ASP-style tags, you need - to set the <link linkend="ini.asp-tags">asp_tags</link> - &php.ini; variable, or use the - appropriate Apache directive. + ×î¼òµ¥µÄ·½·¨ÊÇÈà PHP ´úÂëÒ²ÄÜʹÓà ASP ±ê¼Ç¡£Õâ¿ÉÒÔÈÃÄãÓà ASP ·ç¸ñµÄ <% ºÍ %> ´úÂ붨½ç·û¡£Ò»Ð©Á÷ÐÐµÄ + HTML ±à¼Æ÷ÔÚ´¦Àí´Ë¸ñʽÉϸü¼ÓÖÇÄÜ»¯Ò»Ð©£¨Ä¿Ç°Èç´Ë£©¡£ÒªÊ¹Óà ASP ·ç¸ñµÄ±ê¼Ç£¬ÄãÐèÒªÔÚ &php.ini; Öдò¿ª + <link linkend="ini.asp-tags">asp_tags</link>£¬»òÕßÓÃÏàÓ¦µÄ Apache ÅäÖÃÑ¡Ïî¡£ </para> </answer> </qandaentry> @@ -251,18 +205,14 @@ <qandaentry id="faq.using.variables"> <question> <para> - Where can I find a complete list of pre-set variables available - to me, and why are these not documented in the PHP documentation? + ÄÄÀï¿ÉÒÔÕÒµ½ËùÓпÉÓõÄÔ¤¶¨Òå±äÁ¿µÄÍêÕûÁÐ±í£¿ÎªÊ²Ã´ÔÚ PHP ÎĵµÖÐûÓУ¿ </para> </question> <answer> <para> - The best way is to stick a <literal><?php phpinfo(); ?></literal> - part on a page and load it up. This will show you all sorts of - information about your PHP setup, including a list of both - environment variables and also special variables set by your - web server. This list can't really be documented in the PHP - documentation because it will change from one server to another. + ×îºÃµÄ·½·¨ÊÇ°Ñ <literal><?php phpinfo(); ?></literal> Õ³Ìùµ½Ä³Ò»Ò³²¢´ò¿ªÀ´¿´¿´¡£Ëü½«ÏÔʾÄãµÄ + PHP µÄËùÓÐÖÖÀàµÄÉèÖ㬰üÀ¨»·¾³±äÁ¿ºÍ web ·þÎñÆ÷É趨µÄÌØÊâ±äÁ¿µÄÁÐ±í¡£Õâ¸öÁÐ±í²»ÄÜ·ÅÔÚ + PHP ÎĵµÖУ¬ÒòΪËüÔÚ²»Í¬µÄ·þÎñÆ÷Öлá¸Ä±äµÄ¡£ </para> </answer> </qandaentry> @@ -270,17 +220,14 @@ <qandaentry id="faq.using.cgi-vars"> <question> <para> - I'm trying to access one of the standard CGI - variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined - function, and it can't seem to find it. What's wrong? + ÎÒÊÔ×ÅÔÚÓû§×Ô¶¨Ò庯ÊýÖзÃÎÊÒ»¸ö±ê×¼µÄ CGI ±äÁ¿£¨ÀýÈç $DOCUMENT_ROOT »ò $HTTP_REFERER£©£¬µ«ÊÇÕÒ²»µ½£¬ÄÄÀï³öÁË´í£¿ </para> </question> <answer> <para> - Environment variables are normal global variables, so you must - either declare them as global variables in your function (by using - "<literal>global $DOCUMENT_ROOT;</literal>", for example) or by using - the global variable array (ie, "<literal>$GLOBALS["DOCUMENT_ROOT"]</literal>". + »·¾³±äÁ¿Í¨³£¶¼ÊÇÈ«¾Ö±äÁ¿£¬Òò´ËÄã±ØÐëÔÚÄãµÄº¯ÊýÖÐÉùÃ÷ËüÃÇΪȫ¾Ö±äÁ¿£¨ÀýÈçÓà + <literal>global $DOCUMENT_ROOT;</literal>£©£¬»òÕßÓÃÈ«¾Ö±äÁ¿Êý×飨ÀýÈç + <literal>$GLOBALS["DOCUMENT_ROOT"]</literal>£©¡£ </para> </answer> </qandaentry>
Index: phpdoc-zh/faq/using.xml diff -u phpdoc-zh/faq/using.xml:1.1 phpdoc-zh/faq/using.xml:1.2 --- phpdoc-zh/faq/using.xml:1.1 Mon Sep 2 16:29:28 2002 +++ phpdoc-zh/faq/using.xml Tue Sep 3 23:43:26 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="gb2312"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $Author: dallas $ --> <!-- EN-Revision:1.19 Maintainer: dallas Status: ready --> <chapter id="faq.using"> @@ -7,30 +7,23 @@ <titleabbrev>ʹÓà PHP</titleabbrev> <para> - This section gathers most common errors you can - face, while writing PHP scripts. + ±¾½Ú»ã¼¯ÁËÄãÔÚд PHP ½Å±¾Ê±Åöµ½µÄ´ó¶àÊýÆÕͨ´íÎó¡£ </para> <qandaset> <qandaentry id="faq.using.anyform"> <question> <para> - I would like to write a generic PHP script that can handle data coming - from any form. How do I know which POST method variables are available? + ÎÒÏëдһ¸ö¿ÉÒÔ´¦ÀíÈÎºÎ±íµ¥À´µÄÊý¾ÝµÄͨÓà PHP ½Å±¾¡£ÎÒÔõô֪µÀÄĸö POST ·½·¨±äÁ¿¿ÉÓÃÄØ£¿ </para> </question> <answer> <para> - Make sure that the <link linkend="ini.track-vars">track_vars</link> - feature is enabled in your &php.ini; - file. Since PHP 4.0.3, this feature is always on. When - <literal>track_vars</literal> is on, it creates some - associative arrays, the most important here is: - <literal>$_POST</literal> (this used to be called - <literal>$HTTP_POST_VARS</literal> in <literal>PHP</literal> versions - prior 4.1.0). So, to write a generic - script to handle POST method variables you would - need something similar to the following: + È·±£ÔÚ &php.ini ÎļþÖ줻îÁË <link linkend="ini.track-vars">track_vars</link> ÌØÐÔ¡£×Ô´Ó PHP 4.0.3 + ¿ªÊ¼£¬´ËÌØÐÔ×ÜÊÇ´ò¿ªµÄ¡£µ± <literal>track_vars</literal> + ´ò¿ªÊ±£¬»á½¨Á¢Ò»Ð©Ïà¹ØµÄÊý×飬ÕâÀï×îÖØÒªµÄÊÇ£º<literal>$_POST</literal>£¨ÔÚ <literal>PHP</literal> 4.1.0 + ֮ǰ½Ð×ö <literal>$HTTP_POST_VARS</literal>£©¡£Òò´ËҪд³ö´¦Àí POST + ·½·¨±äÁ¿µÄͨÓýű¾ÄãÐèҪһЩÀàËÆÈçÏµķ½·¨£º <programlisting role="php"> <![CDATA[ foreach ($_POST as $var => $value) { @@ -45,17 +38,13 @@ <qandaentry id="faq.using.singlequotes"> <question> <para> - I need to convert all single-quotes (') to a backslash - followed by a single-quote. How can I do this with a - regular expression? + ÎÒÐèÒª°ÑËùÓеĵ¥ÒýºÅ£¨'£©×ª»»Îª·´Ð±ÏߺóÃæ¸ú×ŵ¥ÒýºÅ¡£ÔõÑùÓÃÕýÔò±í´ïʽ×öµ½ÄØ£¿ </para> </question> <answer> <para> - First off, take a look at the <function>addslashes</function> - function. It will do exactly what you want. You should also have - a look at the <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> - directive in your &php.ini; file. + Ê×ÏÈ¿´¿´ <function>addslashes</function> º¯Êý¡£ËüÕýÊÇ×öÕâ¼þʵġ£Í¬ÑùÒ²¿´¿´ÄãµÄ + &php.ini; ÎļþÖÐµÄ <link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link> Ñ¡Ïî¡£ </para> </answer> </qandaentry> @@ -63,8 +52,8 @@ <qandaentry id="faq.using.wrong-order"> <question> <para> - When I do the following, the output is printed in - the wrong order: + µ±ÎÒÕâÑù×öʱ£¬Êä³öÏÔʾµÄ´ÎÐòÊÇ´íµÄ£º + <programlisting role="php"> function myfunc($argument) { @@ -73,15 +62,13 @@ $variable = 10; echo "myfunc($variable) = " . myfunc($variable); </programlisting> - what's going on? + ÕâÊÇÔõô»ØÊ£¿ </para> </question> <answer> <para> - To be able to use the results of your function in an expression (such - as concatenating it with other strings in the example above), you need - to <emphasis>return</emphasis> the value, not <function>echo</function> - it. + ÒªÔÚÒ»¸ö±í´ïʽÖУ¨ÀýÈçÔÚÉÏÃæµÄÀý×ÓÖÐºÍÆäËü×Ö·û´®Á¬½Ó£©Ê¹Óú¯ÊýµÄ½á¹û£¬ÄãÐèÒªÓà + <emphasis>return</emphasis> ·µ»ØÕâ¸öÖµ£¬¶ø²»ÊÇ <function>echo</function> Ëü¡£ </para> </answer> </qandaentry> @@ -89,7 +76,7 @@ <qandaentry id="faq.using.newlines"> <question> <para> - Hey, what happened to my newlines? + ÏÂÃæ´úÂëÔõôûÓзֳÉÁ½ÐÐÏÔʾ£¿ <programlisting role="php"> <![CDATA[ <pre> @@ -102,18 +89,12 @@ </question> <answer> <para> - In PHP, the ending for a block of code is either "?>" or - "?>\n" (where \n means a newline). So in the example above, - the echoed sentences will be on one line, because PHP omits - the newlines after the block ending. This means that you need to - insert an extra newline after each block of PHP code to make - it print out one newline. + ÔÚ PHP ÖУ¬Ò»¶Î´úÂëµÄ½áÊø±ê¼ÇҪôÊÇ¡°?>¡±ÒªÃ´ÊÇ¡°?>\n¡±£¨\n ±íʾ»»ÐУ©¡£Òò´ËÔÚÉÏÃæµÄÀý×ÓÖУ¬Êä³öµÄ¾ä×Ó½«ÏÔʾÔÚͬһÐÐÖУ¬ÒòΪ + PHP ºöÂÔÁË´úÂë½áÊø±ê¼ÇºóÃæµÄ»»ÐС£ÕâÒâζ×ÅÈç¹ûÒªÊä³öÒ»¸ö»»Ðзû£¬ÄãÐèÒªÔÚÿ¶Î + PHP ´úÂëµÄ½áÊø±ê¼ÇºóÃæ¶à¼ÓÒ»¸ö»»ÐС£ </para> <para> - Why does PHP do this? Because when formatting normal HTML, this - usually makes your life easier because you don't want that newline, - but you'd have to create extremely long lines or otherwise make the - raw page source unreadable to achieve that effect. + PHP ΪʲôÕâô×öÄØ£¿ÒòΪÔÚ¸ñʽ»¯Õý³£µÄ HTML ʱ£¬ÕâÑùͨ³£»á¸üÈÝÒס£¼ÙÈçÊä³öÁË»»ÐжøÄã²»ÐèÒªÕâ¸ö»»ÐÐʱ£¬Äã¾Í²»µÃ²»ÓÃÒ»¸ö·Ç³£³¤µÄÐÐÀ´´ïµ½ÕâÑùµÄЧ¹û£¬»òÕßÈòúÉúµÄ HTML Ò³ÃæµÄÔ´ÎļþµÄ¸ñʽºÜÄѶÁ¡£ </para> </answer> </qandaentry> @@ -121,17 +102,13 @@ <qandaentry id="faq.using.headers-sent"> <question> <para> - I get the message 'Warning: Cannot send session cookie - headers already - sent...' or 'Cannot add header information - headers already sent...'. + Îҵõ½ÏûÏ¢¡°Warning: Cannot send session cookie - headers already + sent...¡±»òÕß¡°Cannot add header information - headers already sent...¡±¡£ </para> </question> <answer> <para> - The functions <function>header</function>, - <function>setcookie</function> and the session functions need to add - headers to the output stream. But headers can only be sent before all other - content, check if your script is sending headers after having already sent - content. + º¯Êý <function>header</function>£¬<function>setcookie</function> ºÍ session º¯ÊýÐèÒªÔÚÊä³öÁ÷ÖÐÔö¼Ó±¨Í·¡£µ«ÊDZ¨Í·Ö»ÄÜÔÚÆäËüÈκÎÊä³öÄÚÈÝ֮ǰ·¢ËÍ£¬¼ì²éÄãµÄ´úÂëÊÇ·ñÔÚÈκÎÒѾ·¢Ë͵ÄÄÚÈݺóÃæ·¢Ëͱ¨Í·¡£ </para> </answer> </qandaentry> @@ -139,15 +116,12 @@ <qandaentry id="faq.using.header"> <question> <para> - I need to access information in the request header directly. - How can I do this? + ÎÒÐèÒªÖ±½Ó·ÃÎÊÇëÇó±¨Í·ÖеÄÐÅÏ¢£¬ÔõôÄܰ쵽? </para> </question> <answer> <para> - The <function>getallheaders</function> function will do this if - you are running PHP as an Apache module. So, the following bit - of code will show you all the request headers: + Èç¹ûÄãÒÔ Apache µÄÄ£¿é·½Ê½ÔËÐÐ PHP£¬ÄÇôº¯Êý <function>getallheaders</function> ¿ÉÒÔ×öÕâ¼þÊ¡£Òò´ËÏÂÃæµÄ´úÂë¿ÉÒÔÏÔʾËùÓеÄÇëÇó±¨Í·£º <programlisting role="php"> <![CDATA[ $headers = getallheaders(); @@ -163,20 +137,15 @@ <qandaentry id="faq.using.authentication"> <question> <para> - When I try to use authentication with IIS I get 'No Input file specified'. + µ±ÎÒÓà IIS ½øÐÐ HTTP ÈÏ֤ʱµÃµ½¡°No Input file specified¡±ÏûÏ¢¡£ </para> </question> <answer> <para> - The security model of IIS is at fault here. This is a problem - common to all CGI programs running under IIS. A workaround is - to create a plain HTML file (not parsed by PHP) as the entry page - into an authenticated directory. Then use a META tag to redirect - to the PHP page, or have a link to the PHP page. PHP will - then recognize the authentication correctly. With the ISAPI - module, this is not a problem. This should not effect other - NT web servers. For more information, see: - <ulink url="&faqurl.iis;">&faqurl.iis;</ulink>. + IIS µÄ°²È«Ä£ÐÍÕâÀïÓÐ벡¡£ÕâÊÇËùÓÐ IIS ÏÂÔËÐÐµÄ CGI ³ÌÐòËù¹²ÓеÄÎÊÌâ¡£Ò»¸ö½â¾ö°ì·¨Êǽ¨Á¢Ò»¸ö´¿ + HTML Îļþ£¨²»¾¹ý PHP ½âÎö£©×÷ΪҪ½øÈëÈÏ֤Ŀ¼µÄµÇÂ¼Ò³Ãæ£¬È»ºóÓà META ±ê¼ÇÀ´Öض¨Ïòµ½ + PHP Ò³Ãæ£¬»òÕßÓÃÒ»¸öÁ¬½Óµ½ PHP Ò³Ãæ¡£È»ºó PHP ¾Í¿ÉÒÔÕýȷʶ±ðÈÏÖ¤ÐÅÏ¢ÁË¡£Èç¹ûÊÇÓà + ISAPI Ä£¿é£¬ÄÇûÓÐÕâ¸öÎÊÌâ¡£ÆäËü NT Ï嵀 web ·þÎñÆ÷²»ÊÜ´ËÓ°Ïì¡£¸ü¶àÐÅÏ¢¼û£º<ulink url="&faqurl.iis;">&faqurl.iis;</ulink>¡£ </para> </answer> </qandaentry> @@ -184,28 +153,22 @@ <qandaentry id="faq.using.netscape"> <question> <para> - My PHP script works on IE and Lynx, but on Netscape some of - my output is missing. When I do a "View Source" I see the - content in IE but not in Netscape. + ÎÒµÄ PHP ½Å±¾ÔÚ IE ºÍ Lynx ÏÂÄܹ¤×÷£¬µ«ÊÇÔÚ Netscape ÖÐÓеÄÊä³ö¶ªÊ§ÁË¡£µ±ÎÒÓᰲ鿴ԴÎļþ¡±Ê±¿ÉÒÔÔÚ + IE Öп´µ½ÄÚÈÝ£¬µ«ÊÇ Netscape Öв»ÄÜ¡£ </para> </question> <answer> <para> - Netscape is more strict regarding html tags (such as tables) then - IE. Running your html output through a html validator, such as - <ulink url="&faqurl.w3.validator;">validator.w3.org</ulink>, might - be helpful. For example, a missing </table> might cause this. + Netscape ÔÚ¹ØÓÚ html ±ê¼Ç£¨ÀýÈç table£©ÉÏ±È IE ¸üÑϸñ¡£ÓÃÒ»¸ö html ÑéÖ¤Æ÷£¬ÀýÈç + <ulink url="&faqurl.w3.validator;">validator.w3.org</ulink> À´ÑéÖ¤ÄãµÄ html + Êä³ö¿ÉÄÜ»áÓаïÖú¡£ÀýÈç©ÁË </table> ¿ÉÄܻᵼÖÂÕâÑùµÄ½á¹û¡£ </para> <para> - Also, both IE and Lynx ignore any NULs (<literal>\0</literal>) in - the HTML stream, Netscape does not. The best way to check for this is - to compile the <link linkend="features.commandline">command line</link> version of - PHP (also known as the CGI version) and run your script from the - command line. In *nix, pipe it through <literal>od -c</literal> and look - for any <literal>\0</literal> characters. If you are on Windows you need - to find an editor or some other program that lets you look at binary files. - When Netscape sees a NUL in a file it will typically not output anything - else on that line whereas both IE and Lynx will. + ͬÑù£¬IE ºÍ Lynx ¶¼ºöÂÔÁË HTML Á÷ÖеÄÈκΠNULs£¨<literal>\0</literal>£©£¬Netscape + ¾Í²»¡£×îºÃµÄ¼ì²é·½·¨ÊDZàÒë <link linkend="features.commandline">PHP µÄÃüÁîÐÐģʽ</link>°æ±¾£¨Ò²³ÆÎª + CGI °æ±¾£©²¢´ÓÃüÁîÐÐÔËÐÐÄãµÄ½Å±¾¡£ÔÚ *nix ÖУ¬ÓùܵÀ´«µÝµ½ <literal>od -c</literal> ²¢²é¿´ÈκΠ+ <literal>\0</literal> ×Ö·û¡£Èç¹ûÔÚ Windows ÏÂÄãÐèÒªÄܹ»²é¿´¶þ½øÖÆÎļþ¸ñʽµÄ±à¼Æ÷»ò³ÌÐò¡£µ± + Netscape Åöµ½ NUL ʱ¾Í²»»áÊä³öÖ®ºó¸ÃÐеÄÈκÎÄÚÈݶø IE ºÍ Lynx ¶¼»á¡£ </para> </answer> </qandaentry> @@ -213,17 +176,13 @@ <qandaentry id="faq.using.mixml"> <question> <para> - How am I supposed to mix XML and PHP? It complains - about my <?xml> tags! + ÎÒÔõÑù»ìºÏʹÓà XML ºÍ PHP£¿Ëü²»ÈÏÎÒµÄ <?xml> ±ê¼Ç£¡ </para> </question> <answer> <para> - You need to turn off the short tags by setting - <link linkend="ini.short-open-tag">short_tags</link> to 0 in your - &php.ini; file, or by using the appropriate - Apache directive. You could even use a <File> section to - do this selectively. + ÄãÐèÒªÔÚ &php.ini; ÎļþÖÐͨ¹ýÉ趨 <link linkend="ini.short-open-tag">short_tags</link> Ϊ 0 + À´¹Ø±Õ PHP µÄ¼ò¶Ì±ê¼Ç¸ñʽ£¬»òÕßͨ¹ýÏàÓ¦µÄ Apache Ñ¡Ïî¡£ÄãÉõÖÁÓ¦¸ÃÓà <File> ¶ÎÂäÀ´Ñ¡ÔñÐÔµÄÕâÑù×ö¡£ </para> </answer> </qandaentry> @@ -231,19 +190,14 @@ <qandaentry id="faq.using.editor"> <question> <para> - How can I use PHP with FrontPage or some other HTML editor - that insists on moving my code around? + ÔõÑùÓà FrontPage »òÕ߯äËü·ÇÒª°ÑÎҵĴúÂëÒÆÀ´ÒÆÈ¥µÄ HTML ±à¼Æ÷À´±à¼ PHP£¿ </para> </question> <answer> <para> - One of the easiest things to do is to enable using ASP tags in your - PHP code. This allows you to use the ASP-style <% and %> code - delimiters. Some of the popular HTML editors handle those more - intelligently (for now). To enable the ASP-style tags, you need - to set the <link linkend="ini.asp-tags">asp_tags</link> - &php.ini; variable, or use the - appropriate Apache directive. + ×î¼òµ¥µÄ·½·¨ÊÇÈà PHP ´úÂëÒ²ÄÜʹÓà ASP ±ê¼Ç¡£Õâ¿ÉÒÔÈÃÄãÓà ASP ·ç¸ñµÄ <% ºÍ %> ´úÂ붨½ç·û¡£Ò»Ð©Á÷ÐÐµÄ + HTML ±à¼Æ÷ÔÚ´¦Àí´Ë¸ñʽÉϸü¼ÓÖÇÄÜ»¯Ò»Ð©£¨Ä¿Ç°Èç´Ë£©¡£ÒªÊ¹Óà ASP ·ç¸ñµÄ±ê¼Ç£¬ÄãÐèÒªÔÚ &php.ini; Öдò¿ª + <link linkend="ini.asp-tags">asp_tags</link>£¬»òÕßÓÃÏàÓ¦µÄ Apache ÅäÖÃÑ¡Ïî¡£ </para> </answer> </qandaentry> @@ -251,18 +205,14 @@ <qandaentry id="faq.using.variables"> <question> <para> - Where can I find a complete list of pre-set variables available - to me, and why are these not documented in the PHP documentation? + ÄÄÀï¿ÉÒÔÕÒµ½ËùÓпÉÓõÄÔ¤¶¨Òå±äÁ¿µÄÍêÕûÁÐ±í£¿ÎªÊ²Ã´ÔÚ PHP ÎĵµÖÐûÓУ¿ </para> </question> <answer> <para> - The best way is to stick a <literal><?php phpinfo(); ?></literal> - part on a page and load it up. This will show you all sorts of - information about your PHP setup, including a list of both - environment variables and also special variables set by your - web server. This list can't really be documented in the PHP - documentation because it will change from one server to another. + ×îºÃµÄ·½·¨ÊÇ°Ñ <literal><?php phpinfo(); ?></literal> Õ³Ìùµ½Ä³Ò»Ò³²¢´ò¿ªÀ´¿´¿´¡£Ëü½«ÏÔʾÄãµÄ + PHP µÄËùÓÐÖÖÀàµÄÉèÖ㬰üÀ¨»·¾³±äÁ¿ºÍ web ·þÎñÆ÷É趨µÄÌØÊâ±äÁ¿µÄÁÐ±í¡£Õâ¸öÁÐ±í²»ÄÜ·ÅÔÚ + PHP ÎĵµÖУ¬ÒòΪËüÔÚ²»Í¬µÄ·þÎñÆ÷Öлá¸Ä±äµÄ¡£ </para> </answer> </qandaentry> @@ -270,17 +220,14 @@ <qandaentry id="faq.using.cgi-vars"> <question> <para> - I'm trying to access one of the standard CGI - variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined - function, and it can't seem to find it. What's wrong? + ÎÒÊÔ×ÅÔÚÓû§×Ô¶¨Ò庯ÊýÖзÃÎÊÒ»¸ö±ê×¼µÄ CGI ±äÁ¿£¨ÀýÈç $DOCUMENT_ROOT »ò $HTTP_REFERER£©£¬µ«ÊÇÕÒ²»µ½£¬ÄÄÀï³öÁË´í£¿ </para> </question> <answer> <para> - Environment variables are normal global variables, so you must - either declare them as global variables in your function (by using - "<literal>global $DOCUMENT_ROOT;</literal>", for example) or by using - the global variable array (ie, "<literal>$GLOBALS["DOCUMENT_ROOT"]</literal>". + »·¾³±äÁ¿Í¨³£¶¼ÊÇÈ«¾Ö±äÁ¿£¬Òò´ËÄã±ØÐëÔÚÄãµÄº¯ÊýÖÐÉùÃ÷ËüÃÇΪȫ¾Ö±äÁ¿£¨ÀýÈçÓà + <literal>global $DOCUMENT_ROOT;</literal>£©£¬»òÕßÓÃÈ«¾Ö±äÁ¿Êý×飨ÀýÈç + <literal>$GLOBALS["DOCUMENT_ROOT"]</literal>£©¡£ </para> </answer> </qandaentry>