text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
Show all predefined variables with phpinfo()
|
例 2-3 phpinfo() で定義済みの変数を全て表示する
|
If you load up this file in your browser you will see a page full of information about PHP along with a list of all the variables available to you.
|
ブラウザにこのファイルを読み込むと、利用可能な全ての変数のリストとともに PHPに関する全ての情報を参照することができます。
|
For example, if we wanted to check for Internet Explorer we could do something like this:
|
PHPタグの中に複数のPHP命令を置くことができ、echo文以上のことを行なう コードブロックを作成することができます。 例えば、インターネット・エクスプローラかどうかを調べたい場合は、 以下のようにします。
|
?php if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {echo "You are using Internet Explorer br / ";}?
|
例 2-4 制御構造 および 関数 の使用例
|
Here we introduce a couple of new concepts.
|
このスクリプトの出力例は以下のようになります。
|
If it returns TRUE, the if statement evaluates to TRUE If it returns TRUE, the if statement evaluates to TRUE and the code within its {braces} is executed.
|
この例を少し発展させて、PHPブロックの中からでもPHPモードから出たり 入ったりすることができることを以下に示します。
|
We can take this a step further and show how you can jump in and out of PHP mode even in the middle of a PHP block:
|
例 2-5HTMLおよびPHPモードの両方を混在させる
|
Instead of using a PHP echo statement to output something, we jumped out of PHP mode and just sent straight HTML.
|
この例の出力は以下のようになります。
|
Only one of the HTML blocks will end up getting sent to the viewer depending on if strstr() returned TRUE or FALSE In other words, if the string MSIE was found or not.
|
何かを出力する際にPHPのecho文を使用する代わりに、PHPモードを抜けて、 通常のHTMLを送信しています。ここで注意すべき重要で強力な点は、 スクリプトの論理フローが損なわれないということです。 strstr() が TRUE または FALSE のどちらを 返すか、言い換えると MSIE が見つかったかどうかに 基づき、HTMLブロックだけが見る側に送信されることになります。
|
You can also find other examples on the php.net websites in the links section: http: / /www.php.net / links.php.
|
ここで得た知識により、マニュアルのほとんどの部分と サンプルのアーカイブにある多くのスクリプトの例を理解できる ようになったはずです。他の例をWebサイトphp.netにあるリンク セクション http://www.php.net/links.php で 探すこともできます。
|
Prev
|
zlib: PHP 4.0.4 - PHP 4.2.3 (fopencookieを有するシステムのみ)
|
List of Supported Protocols / Wrappers
|
compress.zlib:// および compress.bzip2:// PHP 4.3以降
|
PHP 4.0.4 - PHP 4.2.3 (systems with fopencookie only)
|
zlib:
|
zlib:
|
compress.zlib://
|
compress.bzip2: / /
|
compress.bzip2://
|
This is deprecated as of PHP 4.3 due to ambiguities with filenames containing ':' characters; use compress.zlib: / / instead.
|
zlib: は、 gzopen() と同様に 動作しますが、このストリームは fread() および他 のファイルシステム関数と組み合わせて使用することができるところが異 なります。この機能ではファイル名に':'文字が含まれる曖昧さがあるた め、PHP 4.3以降では古い機能となっています。代わりに compress.zlib:// を使用して下さい。
|
Prev
|
compress.zlib:// および compress.bzip2:// は、それぞれ gzopen() および bzopen() と等 価で、fopencookieをサポートしないシステムの上でも動作します。
|
Prev
|
PHP 3, PHP 4. ftps:// since PHP 4.3
|
List of Supported Protocols / Wrappers
|
ftp://example.com/pub/file.txt
|
ftp: / /example.com / pub / file.txt
|
ftp://user:[email protected]/pub/file.txt
|
ftps: / /example.com / pub / file.txt
|
ftps://example.com/pub/file.txt
|
Allows read access to existing files and creation of new files via FTP.
|
ftps://user:[email protected]/pub/file.txt
|
You can open files for either reading or writing, but not both simultaneously.
|
FTPにより既存のファイルに読み込みアクセスをしたり、新規にファイル を作成することができます。サーバがパッシブモードftpをサポートしな い場合、接続は失敗します。
|
If you need to update existing files over ftp, use ftp_connect().
|
読み込み用または書き込み用でファイルをオープンすることが可能ですが、 読み書き両用でオープンすることはできません。 ftpサーバにあるファイルが既に存在する場合、そのファイルを書き込み 用にオープンしようとした場合には、接続は失敗します。 既存のファイルをftpにより更新する必要がある場合には、 ftp_connect() を使用して下さい。
|
If the server does not support SSL, then the connection falls back to regular unencrypted ftp.
|
ftps:// は PHP 4.3で導入されました。 これは、 ftp:// と同じですが、ftpサーバについて セキュアな接続の確立を試みます。 サーバがSSLをサポートしない場合、接続は通常の暗号化されないftp接続 で代用されます。
|
Prev
|
注意 FTPSは、PHP 4.3以降でサポートされており、OpenSSLのサポートを有効 にしていることが必要です。
|
In addition to these wrappers, as of PHP 4.3, you can write your own wrappers using PHP script and stream_register_wrapper().
|
fopen() and copy() のようなファ イルシステム関数で使用するためにPHPに組み込まれたURL型式のプロトコ ルの一覧を示します。これらのラッパーに加えて、PHP 4.3以降では、PHP スクリプトと stream_register_wrapper() により、ユー ザ独自のラッパーを書くことができます。
|
PHP 3, PHP 4. https: / / since PHP 4.3
|
PHP 3, PHP 4。PHP 4.3以降では https://
|
http: / /example.com
|
http://example.com
|
http: / /user:[email protected]
|
http://user:[email protected]
|
https: / /example.com
|
https://example.com
|
https: / /user:[email protected]
|
https://user:[email protected]
|
A Host: A Host: header is sent with the request to handle name-based virtual hosts.
|
HTTP 1.0によりHTTP GETメソッドを用いてファイル/リソースに読み込み のみのアクセスが可能です。仮想ホストにホスト名でアクセスするために、 Host: ヘッダが送信されます。 iniファイルまたはストリームコンテキストにより、 user_agent 文字列を設定してい る場合、リクエストの中にも含まれます。
|
Redirects have been supported since PHP 4.0.5; if you are using an earlier version you will need to include trailing slashes in your URLs.
|
PHP 4.0.5以降、リダイレクトがサポートされています。これ以前のバー ジョンを使用している場合、URLの末尾にスラッシュを付ける必要があり ます。
|
Since PHP 4.3, the headers are available using stream_get_meta_data().
|
ストリームにより、リソースの 本体 にアクセスで きるようになります。ヘッダは、 $http_response_header 変数に保存されます。 PHP 4.3以降、ヘッダは、 stream_get_meta_data() に よりアクセス可能です。
|
Note:
|
HTTP 接続は、読み込みのみ可です。HTTPリソースにデータを書き込んだ り、ファイルをコピーすることはできません。
|
Prev
|
注意 HTTPSは、PHP 4.3以降でサポートされており、OpenSSLのサポートを有効 にした場合のみ使用できます。
|
Prev
|
PHP 3.0.13以降、 php://output 、そして、 PHP 4.3以降、 php://input
|
Appendix I.
|
php://stdin
|
Next
|
php://stdout
|
PHP 3.0.13 and up, php: / /output and php: / /input since PHP 4.3
|
php://stderr
|
php: / /stdout
|
php://output
|
php: / /output
|
php://input
|
php: / /stdin, php: / /stdout and php: / /stderr allow access to the corresponding input or output stream of the PHP process.
|
php://stdin 、 php://stdout と php://stderr により、対応するPHPプロセスの 入力または出力ストリームにアクセスできるようになります。
|
php: / /input allows you to read raw POST data.
|
php://output により、 print() および echo() と同様の 手法により、出力バッファに書き込むことができるようになります。
|
php: / /stdin and php: / /input are read-only, whereas php: / /stdout, php: / /stderr and php: / /output are write-only.
|
php://input により、raw POSTデータを読み込む ことができるようになります。これは、 $HTTP_RAW_POST_DATA よりメモリ消費量が少なく、 代わりとなるものです。また、特別な php.ini ディレクティブを全く必 要としません。
|
Compression Streams
|
php://stdin および php://input は読み込みのみ可です。一方、 php://stdout, php://stderr および php://output は、書き込みのみ可です。
|
Table 42-1.
|
A set of macros was introduced into Zend's API that simplify access to zval containers (see 表42-1).
|
Macro
|
表 42-1API Macros for Accessing zval Containers
|
Arrays and objects are converted based on the number of entries or properties, respectively, that they have.
|
To work around this, you have to use a set of API functions to force a type conversion on every argument that's being passed (see 表32-1).
|
Strings containing a number are converted to their corresponding numeric representation, otherwise resulting in 0.0.
|
Note: All conversion functions expect a **zval as parameter.
|
Longs and doubles are converted to their corresponding string representation.
|
表 32-1Argument Conversion Functions
|
All other types result in an object with the property scalar, having the corresponding source value as content.
|
注意 You can find a demonstration of the behavior in cross_conversion.php on the accompanying CD-ROM. 図32-2 shows the output.
|
Figure 32-2 shows the output.
|
図 32-2Cross-conversion behavior of PHP.
|
zval **parameter; if((ZEND_NUM_ARGS() != 1) _BAR_ _BAR_ (zend_get_parameters_ex(1, parameter) != SUCCESS)) {WRONG_PARAM_COUNT;} convert_to_long_ex(parameter); RETURN_LONG(Z_LVAL_P(parameter));
|
Following is a quote from the sample module discussed previously, which makes use of the conversion functions:
|
PHP / Zend zval type definition.
|
例 32-2PHP/Zend zval type definition.
|
The substructure zvalue_value is a union that contains the variable 's contents.
|
表 32-2Zend zval Structure
|
For a description of both structures, see Table 32-2, Table 32-3 and Table 32-4.
|
表 32-3Zend zvalue_value Structure
|
For every new reference to the value stored in this variable, this counter is increased by 1.
|
表 32-4Zend Variable Type Constants
|
When the reference counter reaches 0, no references exist to this value anymore, which causes automatic freeing of the value.
|
To access a long you access zval.value.lval, to access a double you use zval.value.dval, and so on. Because all values are stored in a union, trying to access data with incorrect union members results in meaningless output.
|
Because all values are stored in a union, trying to access data with incorrect union members results in meaningless output.
|
Accessing arrays and objects is a bit more complicated and is discussed later.
|
Of course, you can change any zval containers that you created within your function, but you mustn 't change any zval s that refer to Zend-internal data!
|
If your function accepts arguments passed by reference that you intend to modify, you need to take some precautions.
|
Because the *_ex() API doesn't perform zval separation, it's considerably faster, while at the same time disabling write access.
|
This action is called zval separation (or pval separation). Because the *_ex() API doesn't perform zval separation, it's considerably faster, while at the same time disabling write access.
|
All other parameters that are not passed by reference are in a read-only state.
|
But this is not the case with regular parameters! All other parameters that are not passed by reference are in a read-only state.
|
Examples are given in in Example 32-3.
|
例 32-3Testing for referenced parameter passing.
|
After having checked the number of arguments, you need to get access to the arguments themselves.
|
Deprecated parameter parsing API This API is deprecated and superseded by the new ZEND parameter parsing API.
|
zend_get_parameters_ex() accepts at least two arguments.
|
After having checked the number of arguments, you need to get access to the arguments themselves. This is done with the help of zend_get_parameters_ex():
|
zend_get_parameters_ex() only checks whether you're trying to retrieve too many parameters.
|
To retrieve more than one argument, you can use a similar snippet:
|
The following code checks for the correct number of arguments:
|
The following code checks for the correct number of arguments:
|
This macro prints a default error message and then returns to the caller.
|
図 32-1 WRONG_PARAM_COUNT in action.
|
ZEND_API void wrong_param_count( void); #define WRONG_PARAM_COUNT {wrong_param_count(); return;}
|
This macro prints a default error message and then returns to the caller. Its definition can also be found in zend_API.h and looks like this:
|
Since PHP 4.1.0, there is a way to do just that by using the new parameter parsing API.
|
New parameter parsing API This chapter documents the new Zend parameter parsing API introduced by Andrei Zmievski. It was introduced in the development stage between PHP 4.0.6 and 4.1.0.
|
int zend_parse_parameters( int num_args TSRMLS_DC, char *type_spec,...);
|
The prototype for parameter parsing function looks like this:
|
Here are some sample error messages:
|
Here are some sample error messages:
|
Warning - ini_get_all() requires at most 1 parameter, 2 given Warning - wddx_deserialize() expects parameter 1 to be string, array given
|
Here is the full list of type specifiers:
|
b - boolean
|
s - string (with possible null bytes) and its length
|
o - object (of any class), stored in zval*
|
r - resource, stored in zval*
|
O - object (of class specified by class entry), stored in zval*
|
a - array, stored in zval*
|
_BAR_ - indicates that the remaining parameters are optional.
|
o - object (of any class), stored in zval*
|
The storage variables corresponding to these parameters should be initialized to default values by the extension, since they will not be touched by the parsing function if the parameters are not passed.
|
O - object (of class specified by class entry), stored in zval*
|
The best way to illustrate the usage of this function is through examples:
|
/ - the parsing function will call SEPARATE_ZVAL_IF_NOT_REF() on the parameter it follows, to provide a copy of the parameter, unless it's a reference.
|
Note that in the last example we pass 3 for the number of received parameters, instead of ZEND_NUM_ARGS().
|
The best way to illustrate the usage of this function is through examples:
|
int zend_parse_parameters_ex( int flags, int num_args TSRMLS_DC, char *type_spec,...);
|
The parsing function has an extended version that allows for an additional flags argument that controls its actions.
|
For even more example, look through the source code for extensions that are shipped with PHP - they illustrate every conceivable situation.
|
With all the abovementioned ways of receiving function parameters you should have a good handle on this process. For even more example, look through the source code for extensions that are shipped with PHP - they illustrate every conceivable situation.
|
Don' t worry if you don't know all the functions used in this source yet; we'll get to them shortly.
|
A very clever implementation of this can be found in the code handling PHP's fsockopen() located in ext/standard/fsock.c, as shown in 例32-1. Don't worry if you don't know all the functions used in this source yet; we'll get to them shortly.
|
Then it uses a fall-through mechanism in a switch() statement to deal with all arguments.
|
例 32-1PHP's implementation of variable arguments in fsockopen().
|
Prev
|
This multiple-stage type of processing, similar to a stairway, allows convenient processing of a variable number of arguments.
|
Prev
|
Note: As you can easily work around the lack of write access in the "traditional" API (with zend_get_parameters() and so on), this API seems to be obsolete, and is not discussed further in this chapter.
|
The default config.m4 shown in Example 27-1 is a bit more complex:
|
Step by step, the process looks like this:
|
Extending_Zend_Build.xml,v 1.8 2002 / 10 / 10 18:13:11 imajes Exp $dnl config.m4 for extension my_module dnl Comments in this file start with the string 'dnl'. dnl Remove where necessary.
|
The default config.m4 shown in 例27-1 is a bit more complex:
|
If you' re unfamiliar with M4 files (now is certainly a good time to get familiar), this might be a bit confusing at first; but it's actually quite easy.
|
例 27-1The default config.m4.
|
The config.m4 file is responsible for parsing the command-line options passed to configure at configuration time.
|
If you're unfamiliar with M4 files (now is certainly a good time to get familiar), this might be a bit confusing at first; but it's actually quite easy.
|
The default file creates two configuration directives in the configure script: --with-my_module and --enable-my_module.
|
Note: Everything prefixed with dnl is treated as a comment and is not parsed.
|
Use the second option when the user simply has to decide whether to enable your extension.
|
The config.m4 file is responsible for parsing the command-line options passed to configure at configuration time. This means that it has to check for required external files and do similar configuration and setup tasks.
|
PHP_EXTENSION( my_module, $ext_shared) fi
|
Note: Be sure to run buildconf every time you change config.m4!
|
We 'll go into more details on the M4 macros available to your configuration scripts later in this chapter.
|
We'll go into more details on the M4 macros available to your configuration scripts later in this chapter. For now, we'll simply use the default files.
|
User functions can be called with the function call_user_function_ex().
|
You can call user functions from your own modules, which is very handy when implementing callbacks; for example, for array walking, searching, or simply for event-based programs.
|
Next is the parameter count as integer and an array containing all necessary parameters.
|
The next argument consists of a pointer to the return value. You don't have to allocate memory for this container; the function will do so by itself. However, you have to destroy this container (using zval_dtor()) afterward!
|
?php dl( "call_userland.so"); function test_function() {print("We are in the test function! br "); return("hello");} $return_value = call_userland("test_function"); print("Return value: \"$return_value\ "br ");?
|
例 38-1Calling user functions.
|
If so, it runs the script unconditionaltest (for example, --with-myext=yes), in which case the value of the option is contained in the variable $withval.
|
表 41-1M4 Macros for config.m4
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.