text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
If you use the octal notation, you must precede the number with a 0 (zero), to use hexadecimal notation precede the number with 0x.
|
æŽæ°(integer)ã¯ã10鲿°(åºåº10)ã16鲿°(åºåº16)ã8鲿°(åºåº8)è¡šèš ã§æå®å¯èœã§ãããªãã·ã§ã³ã§ã笊å·(-ãŸãã¯+)ãåã«ä»ããããšãå¯ èœã§ãã
|
?php $a = 1234; # decimal number $a = -123; # a negative number $a = 0123; # octal number (equivalent to 83 decimal) $a = 0x1A; # hexadecimal number (equivalent to 26 decimal)?
|
8鲿°è¡šèšã䜿çšããå Žåãæ°ã®åã« 0 (ãŒã)ãä» ããå¿
èŠããããŸãããŸãã16鲿°è¡šèšã䜿çšããã«ã¯ãæ°ã®åã« 0x ãä»ããå¿
èŠããããŸãã
|
0[ xX][0-9a-fA-F] + octal:
|
äŸ 7-1æŽæ°ãªãã©ã«
|
If you specify a number beyond the bounds of the integer type, it will be interpreted as a float If you specify a number beyond the bounds of the integer type, it will be interpreted as a float instead.
|
integer åã®ç¯å²å€ã®æ°ãæå®ããå Žåããããã« float ãšããŠè§£éãããŸãããŸããçµæã integer åã®ç¯å²å€ã®æ°ãšãªããããªèšç®ãè¡ããš float ã代ããã«è¿ãããŸãã
|
Unfortunately, there was a bug in PHP so that this does not always work correctly when there are negative numbers involved.
|
ãã®åé¡ã¯PHP 4.1.0ã§è§£æ±ºãããŸããã
|
However, when both operands are positive there is no problem.
|
PHPã«ã¯æŽæ°ã®å²ãç®ã¯ãããŸããã 1/2 㯠floatåã®0.5ã«ãªããŸãã
|
?php var_dump( 25 / 7); / / float(3.5714285714286) var_dump((int) (25 / 7)); / / int(3) var_dump(round(25 / 7)); / / float(4)?
|
integer ã«å€ãæç€ºçã«å€æããã«ã¯ããã£ã¹ã (int) ãŸã㯠(integer) ã®ã© ã¡ããã䜿çšããŠäžãããããããå€ãã®å ŽåãæŒç®åã颿°ãå¶åŸ¡æ§ é ã integer åŒæ°ãå¿
èŠãšããå Žåãå€ã¯èªåçã«å€æã ããããããã£ã¹ãã䜿çšããå¿
èŠã¯ãããŸããã
|
However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires an integer argument.
|
åã®çžäºå€æ ãåç
§äžããã
|
See also type-juggling.
|
FALSE ã¯ã 0 (ãŒã)ãšãªãã TRUE ã¯ã 1 ãšãªããŸãã
|
When converting from float to integer, the number will be rounded towards zero.
|
floatããæŽæ°ã«å€æããå Žåããã®æ°ã¯ãŒãã®æ¹ã«äžžããããŸãã
|
No warning, not even a notice will be issued in this case!
|
floatãæŽæ°ã®ç¯å²(é垞㯠+/- 2.15e+9 = 2^31 )ãè¶ããå Žåãçµæã¯ undefined ãšãªããŸããããã¯ã ãã®floatãæ£ããæŽæ°ã®çµæãåŸãããã«ååãªç²ŸåºŠãåŸãããªã㣠ãããã§ãããã®å ŽåãèŠåãéç¥ãçºçããŸãã!
|
?php echo (int) ((0.1+0.7) * 10); / / echoes 7!?
|
æªç¥ã®ç«¯æ°ã integer ã«ãã£ã¹ãããªãã§äžããããã® å ŽåãäºæããªãçµæãšãªãããšããããŸãã
|
Behaviour of converting to integer is undefined for other types.
|
æåå倿 ãåç
§äžããã
|
However, do not rely on this behaviour, as it can change without notice.
|
æŽæ°ãžã®å€æã®åäœã¯ãä»ã®åã«ã€ããŠã¯å®çŸ©ãããŸãããçŸåšã® åäœã¯ããã®å€ããŸã è«çå€ã«å€æ ããã å Žåãšåãã§ãããããããã®åäœã¯äºåãªãå€æŽ ãããããšãããããã®ã§ããããåæã«ããŠãã¯ãããŸããã
|
NULL is the only possible value of type NULL.
|
ç¹å¥ãª NULL å€ã¯ããã倿°ãå€ãæããªãããšã衚ããŸãã NULL ã¯ãNULLåã®å¯äžã®å€ã§ãã
|
The null type was introduced in PHP 4
|
泚æ NULLåã¯ãPHP 4ã§å°å
¥ãããŸããã
|
it has been assigned the constant NULL.
|
ãã倿°ã¯ä»¥äžã®å Žåã« NULL ãšã¿ãªãããŸãã
|
it has been unset().
|
宿° NULL ã代å
¥ãããŠããå Žåã
|
?php $var = NULL;?
|
äœããã®å€ã代å
¥ãããŠããªãå Žåã
|
Prev
|
unset() ãããŠããå Žåã
|
Resource
|
ãã«åã®å€ã¯äžã€ã ãã§ã倧æåå°æåãåºå¥ããªãããŒã¯ãŒã NULL ã§ãã
|
Pseudo-types used in this documentation
|
is_null() ããã³ unset() ã åç
§ããŠäžããã
|
?php class foo {function do_foo() {echo "Doing foo .";}} $bar = new foo; $bar - do_foo();?
|
ãªããžã§ã¯ããåæåããããã«ã¯ã new åœä»€ ã«ãããªããžã§ã¯ãã®ã€ã³ã¹ã¿ã³ã¹ã倿°ã«äœæããŸãã
|
If a value of any other type is converted to an object, a new instace of the stdClass built in class is created.
|
詳现ãªäºé
ã«ã€ããŠã¯ã ã¯ã©ã¹ããã³ãªããžã§ã¯ã ã« é¢ããã»ã¯ã·ã§ã³ãåç
§äžããã
|
Resources are created and used by special functions.
|
ãªãœãŒã¹ã¯ç¹å¥ãªå€æ°ã§ãããå€éšãªãœãŒã¹ãžã®ãªãã¡ã¬ã³ã¹ãä¿æã㊠ããŸãããªãœãŒã¹ã¯ãç¹å¥ãªé¢æ°ã«ããäœæããã䜿çšãããŸãã ãããã®é¢æ°ããã³å¯Ÿå¿ããå
šãŠã®ãªãœãŒã¹åã®äžèЧã«ã€ããŠã¯ã ä»é² ãåç
§äžããã
|
Note:
|
泚æ ãªãœãŒã¹åã¯ãPHP 4ã§å°å
¥ãããŸããã
|
Due to the reference-counting system introduced with PHP4' s Zend-engine, it is automatically detected when a resource is no longer referred to (just like Java).
|
PHP4ã®Zendãšã³ãžã³ã«å°å
¥ããããªãã¡ã¬ã³ã¹ã«ãŠã³ãã£ã³ã°ã·ã¹ãã ã®ãããã§ããããªãœãŒã¹ãããåç
§ãããªããªã£ãå Žåã«(Javaãšå
šã åæ§ã«)ããã®ãªãœãŒã¹ã¯èªåçã«åé€ãããŸãããã®å Žåããã®ãªãœãŒ ã¹ãäœæããå
šãŠã®ãªãœãŒã¹ã¯ã¬ãŒãããžã³ã¬ã¯ã¿ã«ããéæŸãããŸãã ãã®ãããfree_result 颿°ãçšããŠæåã§ã¡ã¢ãªãéæŸããå¿
èŠãç ããã®ã¯ãŸãã§ãã
|
For this reason, it is rarely ever necessary to free the memory manually by using some free_result function.
|
æ³šæ æç¶çããŒã¿ããŒã¹æ¥ç¶ã¯ç¹å¥ã§ãã¬ãŒãããžã³ã¬ã¯ã¿ã«ããç Žæ£ã ããŸããã æç¶çæ¥ç¶ ãå ç
§äžããã
|
A string literal can be specified in three different ways.
|
string ã¯äžé£ã®æåã§ããPHPã§ã¯ãæåã¯1ãã€ããšåã ã§ããã€ãŸãã256åã®ç°ãªãæåã䜿çšå¯èœã§ããããã¯ãPHPã¯ã UnicodeãããŒãã£ãã«ãµããŒãããŠããªãããšãæå³ããŸãã
|
To specify a literal single quote, you will need to escape it with a backslash (\), like in many other languages.
|
æ³šæ æååãéåžžã«å€§ãããªã£ãŠãåé¡ãããŸãããPHPã«èª²ããããæåå ã®ãµã€ãºã®å®çšäžã®å¶éã¯ãããŸããããã®ãããé·ãæååã«é¢ã㊠æããå¿
èŠã¯å
šããããŸããã
|
Note that if you try to escape any other character, the backslash will also be printed!
|
æååãªãã©ã«ã¯ã3ã€ã®ç°ãªãæ¹æ³ã§æå®ããããšãå¯èœã§ãã
|
?php echo 'this is a simple string'; echo'You can also have embedded newlines in strings this way as it is okay to do'; / / Outputs: "I'll be back "echo'Arnold once said: "I\'ll be back"'; / / Outputs:
|
åŒçšç¬Š
|
This will not expand: \n a newline echo 'This will not expand: \n a newline'; / / Outputs:
|
äºéåŒçšç¬Š
|
If the string is enclosed in double-quotes ("), PHP understands more escape sequences for special characters:
|
ãã¢ãã㥠ã¡ã³ãæ§æ
|
But the most important feature of double-quoted strings is the fact that variable names will be expanded.
|
æååãæå®ããæãç°¡åãªæ¹æ³ã¯ãåŒçšç¬Š(æå ')ã§æ¬ãããšã§ãã
|
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.
|
ãªãã©ã«ã®åŒçšç¬Šæå®ããã«ã¯ãå€ãã®ä»ã®èšèªãšåæ§ã«ããã¯ã¹ã©ã ã·ã¥(\ )ã§ãšã¹ã±ãŒãããå¿
èŠããããŸãã ããã¯ã¹ã©ãã·ã¥ãåŒçšç¬Šã®åãŸãã¯æååã®æåŸã«çœ®ãããå Žåã¯ã 2éã«ããå¿
èŠããããŸãããã®ä»ã®æåããšã¹ã±ãŒãããå Žåã«ã¯ã ããã¯ã¹ã©ãã·ã¥ãåºåãããããšã«æ³šæããŠäžãã! ãã®ãããéåžžã ããã¯ã¹ã©ãã·ã¥èªäœããšã¹ã±ãŒãããå¿
èŠã¯ãããŸããã
|
It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (;).
|
泚æ PHP 3ã§ã¯ããã®å Žåã E_NOTICE ã¬ãã«ã®èŠåã åºåãããŸãã
|
It 's also important to realize that the first character before the closing identifier must be a newline as defined by your operating system.
|
泚æ ä»ã®äºã€ã®æ§æãšç°ãªããåŒçšç¬Šã§æ¬ãããæååã®äžã«ãã倿°ã¯ å±éãããŸããã
|
If this rule is broken and the closing identifier is not "clean" then it's not considered to be a closing identifier and PHP will continue looking for one.
|
æååã2éåŒçšç¬Š(")ã§æ¬ãããå Žå, PHPã¯ããå€ãã®ç¹æ®æåã®ãš ã¹ã±ãŒãã·ãŒã±ã³ã¹ãçè§£ããŸãã
|
Heredoc text behaves just like a double-quoted string, without the double-quotes.
|
衚 7-1ãšã¹ã±ãŒããããæå
|
Variables are expanded, but the same care must be taken when expressing complex variables inside a here doc as with strings.
|
ç¹°ãè¿ããŸããããã®ä»ã®æåããšã¹ã±ãŒãããããšããå Žåã«ã¯ããã ã¯ã¹ã©ãã·ã¥ãåºåãããŸã!
|
EOD; / * More complex example, with variables. * / class foo {var $foo; var $bar; function foo() {$this - foo = 'Foo'; $this - bar = array('Bar1', 'Bar2', 'Bar3');}} $foo = new foo(); $name = 'MyName'; echo EOT My name is "$name ".
|
ããããäºéåŒçšç¬Šã§æ¬ãããæååã§æãéèŠãªã®ã¯ã倿°åãå±é ããããšããã§ãã詳现ã¯ã æååã®ããŒã¹ ã åç
§äžããã
|
The simple syntax is the most common and convenient, it provides a way to parse a variable, an array value, or an object property.
|
æååãåºåãå¥ã®æ¹æ³ãšããŠãã¢ããã¥ã¡ã³ãæ§æ(" ") ããããŸãããã®å ŽåãããIDã ã®åŸ ã«æå®ããæååã眮ããåŸã§ãåãIDãæ¬ããéããããã«çœ®ããŸãã
|
If a dollar sign ($) is encountered, the parser will greedily take as much tokens as possible to form a valid variable name.
|
çµç«¯IDã¯ããã®è¡ã®æåã®ã«ã©ã ããå§ããå¿
èŠããããŸãã䜿çšããã© ãã«ã¯ãPHPã®ä»ã®ã©ãã«ãšåæ§ã®ååã«é¢ããèŠåã«åŸãå¿
èŠããã㟠ããã€ãŸããè±æ°åããã³ã¢ã³ããŒã¹ã³ã¢ã®ã¿ãå«ã¿ãæ°åã§ãªãæå㟠ãã¯ã¢ã³ããŒã¹ã³ã¢ã§å§ãŸãå¿
èŠããããŸãã
|
For a solution, see the complex syntax. echo "This square is $square - width00 centimeters broad .";?
|
ãã¢ããã¥ã¡ã³ãã¯ã2éåŒçšç¬Šã䜿çšããŸãããã2éåŒçšç¬Šã§æ¬ããã æååãšå
šãåæ§ã«åäœããŸãããããããã®å Žåã§ãäžèšã®ãªã¹ãã§ãš ã¹ã±ãŒããããã³ãŒãã䜿çšããããšãå¯èœã§ãã倿°ã¯å±éãããŸããã æååã®å Žåãšåæ§ã«ãã¢ããã¥ã¡ã³ãã®å
éšã§è€éãªå€æ°ã衚ããå Žå ã«ã¯æ³šæãå¿
èŠã§ãã
|
For anything more complex, you should use the complex syntax.
|
äŸ 7-2ãã¢ããã¥ã¡ã³ãã§æååãæ¬ãäŸ
|
This isn 't called complex because the syntax is complex, but because you can include complex expressions this way.
|
泚æ ãã¢ããã¥ã¡ã³ãã¯PHP4ã§è¿œå ãããŸããã
|
You simply write the expression the same way as you would outside the string, and then include it in {and}.
|
ã¹ã¯ãªããã2éåŒçšç¬Šã§æ¬ãããããã¢ããã¥ã¡ã³ãã§æå®ãããå Ž åããã®äžã®å€æ°ã¯ããŒã¹ãããŸãã
|
Some examples to make it clear:
|
æ§æã®åã«ã¯ã åçŽãª æ§æãš è€éãª æ§æã®2çš®é¡ããããŸããç°¡åãªæ§æã¯ãæãäžè¬çã§äŸ¿å©ã§ãã ãã®æ§æã§ã¯ã倿°ãé
åå€ããªããžã§ã¯ãã®ããããã£ãããŒã¹ãã ããšãå¯èœã§ãã
|
This is {fantastic} echo "This is {$great}"; / / Works, outputs:
|
è€éãªæ§æã¯ãPHP 4ã§å°å
¥ãããŸããã ãã®æ§æã¯ãåŒãæ³¢æ¬åŒ§ã§æ¬ãããšã«ããèªèãããŸãã
|
In otherwords, it will still work but / / because PHP first looks for a constant named foo, it will / / throw an error of level E_NOTICE (undefined constant). echo "This is wrong: {$arr[foo][3]}"; / / Works.
|
ãã«èšå·( $)ãèŠä»ãããšããŒãµã¯ãæå¹ãªå€æ° åã圢æããããšãå¯èœãªæé·ã®ããŒã¯ã³ãååŸããŸãã倿°åã®çµ ããæç€ºçã«æå®ãããå Žåã¯ã倿°åãæ³¢æ¬åŒ§ã§æ¬ã£ãŠäžããã
|
Characters within strings may be accessed by specifying the zero-based offset of the desired character after the string in curly braces.
|
åæ§ã«ãé
åæ·»åãšãªããžã§ã¯ãã®ããããã£ãããŒã¹ããããšãå¯ èœã§ããé
åæ·»åã®å Žåãéãè§æ¬åŒ§(']')ã¯æ·»åã®çµããæå³ãã ãªããžã§ã¯ãã®ããããã£ã®å ŽåãåãèŠåãç°¡åãªå€æ°ãšããŠé©çš ãããŸãããããããªããžã§ã¯ãããããã£ã«ã¯ã倿°ã®å Žåã®ãã ãªææ³ã¯ãããŸããã
|
See the string functions section for general functions, the regular expression functions for advanced find replacing (in two tastes:
|
ããè€éãªå Žåã¯ãè€éãªæ§æã䜿çšããå¿
èŠããããŸãã
|
Finally, if you still didn' t find what you're looking for, see also the character type functions.
|
ãã®æ§æã¯ãæ§æãè€éã§ããããã§ã¯ãªãããã®æ¹æ³ã§ã¯è€éãªåŒ ãå«ããããšãã§ãããããè€éãšåŒã°ããŠããŸãã
|
String conversion is automatically done in the scope of an expression for you where a string is needed.
|
äºå®ããã®æ§æã«ããæååã®äžã«åå空éã«ããããããå€ãå«ã ãããšãå¯èœã§ããæååã®å€åŽã«çœ®ãå Žåãšåæ§ã«åŒãæžãããã ã {ãš} ã®éã«å«ããŠäžããã'{'ã¯ãšã¹ã±ãŒãããããšãã§ããªã ããããã®æ§æã¯ $ã{ã®ããåŸã«ç¶ãå Žåã«ã®ã¿èªèãããŸãã (ãªãã©ã«"{$"ãæå®ããã«ã¯ã"{\$"ãŸãã¯"\{$"ã䜿çšããŠäžãã) 以äžã®ããã€ãã®äŸãèŠããšçè§£ãããããªãã§ãããã
|
Reading the manual sections on Types and Type Juggling will make the following clearer.
|
æ³¢æ¬åŒ§ã®åŸã«ä»»æã®æåããŒãããå§ãŸããªãã»ããã§æå®ããããšã« ãããæååå
ã®æåã«ã¢ã¯ã»ã¹ããããšãå¯èœã§ãã
|
Arrays are always converted to the string "Array", so you cannot dump out the contents of an array with echo() or print() to see what is inside them.
|
泚æ éå»ã®äºææ§ã®ãããé
åæ¬åŒ§ã䜿çšããããšãå¯èœã§ãããããã ãã®æ§æã¯PHP 4ã«äŸåããŠããŸãã
|
See below for tips on dumping / viewing the entire contents.
|
äŸ 7-3ããã€ãã®stringã®äŸ
|
If you would like to find out the class name of which an object is an instance of, use get_class().
|
æååã¯ã'.' (ããã)çµåæŒç®åã§çµåããããšãå¯èœã§ãã'+'(ä» å )æŒç®åã¯ãã®äŸã§ã¯åºãŠããªãããšã«æ³šæããŠäžããã詳现ã«ã€ã㊠㯠æååæŒç®å ãåç
§äžããã
|
If you would like to get the type of the resource, use get_resource_type().
|
æååã®ä¿®æ£ãè¡ãå Žåã«äŸ¿å©ãªé¢æ°ããããããããŸãã
|
Look at the functions print_r() and var_dump() for better ways to print out values for debugging.
|
äžè¬çãªé¢æ°ã«ã€ããŠã¯ã æåå颿°ã® ç¯ ãåç
§äžãããé«åºŠãªæ€çŽ¢/眮æãè¡ãæ£èŠè¡šçŸé¢æ°ã«ã€ã㊠ã¯ã Perl ããã³ POSIX æ¡åŒµ ã®2çš®é¡ãããŸãããã ãããã®ç¯ãåç
§äžããã
|
You can also serialize PHP values to XML structures, if you have WDDX support in your PHP setup.
|
URLæååçšé¢æ° ãæååã®æå·å/ 埩å·åçšé¢æ°( mcrypt ããã³ mhash )ããããŸãã
|
The string will evaluate as a float if it contains any of the characters' .', 'e', or'E '.
|
æåŸã«ãæ¢ããŠãããã®ããŸã èŠä»ãããªãå Žåã«ã¯ã æååã®é¢æ° ãåç
§äžããã
|
If the string starts with valid numeric data, this will be the value used.
|
æ°å€ãšããŠæååãè©äŸ¡ãããæãçµæã®å€ãšåã¯æ¬¡ã®ããã« å®çŸ©ãããŸãã
|
Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent.
|
æååã¯ã'.'ã'e'ã'E' ã®ã©ãããå«ãŸããŠããå Žå㯠float ããã以å€ã¯æŽæ°ãšããŠè©äŸ¡ãããŸãã
|
For more information on this conversion, see the Unix manual page for strtod( 3).
|
æåã®åŒãæååã®å Žåã倿°ã®åã¯2çªç®ã®åŒã«äŸåããŸãã
|
?php echo "\$foo==$foo; type is". gettype ($foo). "br / \n";?
|
ãã®å€æã«é¢ãã詳现ã¯ãUNIXããã¥ã¢ã«strtod(3) ãåç
§äžããã
|
Use the functions ord() and chr() to convert between charcodes and characters.
|
æ¬ç¯ã®äŸã詊ãããå Žåããã®äŸãã«ããã¢ã³ãããŒã¹ãããŠãã åäœã確èªããããã«æ¬¡ã®è¡ãæ¿å
¥ããŠäžããã
|
That is to say, if you assign a string value to variable $var, $var becomes a string.
|
PHP ã¯ã倿°å®çŸ©æã«æç€ºçãªåå®çŸ©ãå¿
èŠãš(ãŸãã¯ããµããŒã)ããŸã ãããã倿°ã®åã¯ããã®å€æ°ã䜿çšãããæã«ããå®çŸ©ãããŸãããã ã¯ãããæååã倿° var ã«ä»£å
¥ããå Žåã«ã¯ã var ã¯æååã«ãªãããšãæå³ããŠããŸããã ãæŽæ°å€ã var ã«ä»£å
¥ããå Žåã«ã¯ããã®å€æ° ã¯æŽæ°ã«ãªããŸãã
|
If you then assign an integer value to $var, it becomes an integer.
|
PHP ã®èªåå倿ã®äŸã®äžã€ã¯ãå ç®æŒç®å '+' ã§ãã ãªãã©ã³ãã®ã©ãããfloatã®å Žåãå
šãŠã®ãªãã©ã³ãã¯floatãšããŠè©äŸ¡ ãããçµæã¯floatã«ãªããŸãã ãã®ä»ã®å Žåããªãã©ã³ãã¯æŽæ°ãšããŠè§£éãããçµæãæŽæ°ã«ãªããŸãã ãã®èªåå倿ã¯ãªãã©ã³ãèªäœã®åã倿Žãããã®ã§ã¯ãªããšããããšã« 泚æããŠãã ããã å€ããã®ã¯ããªãã©ã³ããã©ã®ããã«è©äŸ¡ããããã ãã§ãã
|
If any of the operands is a float, then all operands are evaluated as floats, and the result will be a float.
|
æåŸã®äºã€ã®äŸãå¥åŠã«æããå Žåã«ã¯ã æåå倿 ã åç
§ãã ããã
|
Note that this does NOT change the types of the operands themselves; the only change is in how the operands are evaluated.
|
ãã倿°ã匷å¶çã«ããç¹å®ã®åãšããŠè©äŸ¡ããããå Žåã«ã¯ã åãã£ã¹ã ã® ã»ã¯ã·ã§ã³ãåç
§ãã ããããã倿°ã®åã倿Žãããå Žåã«ã¯ã settype() ãåç
§ããŠãã ããã
|
If you wish to force a variable to be evaluated as a certain type, see the section on Type casting.
|
æ¬ç¯ã®äŸããã¹ããããå Žåã«ã¯ã var_dump() ã䜿çšããããšãå¯èœã§ãã
|
If you would like to test any of the examples in this section, you can use the var_dump() function.
|
泚æ é
åãžã®èªå倿ã®åäœã¯çŸæç¹ã§å®çŸ©ãããŠããŸããã
|
?php $a = "1"; / / $a is a string $a[0] = "f"; / / What about string offsets?
|
äžã®äŸã§æããã« $a ã¯é
åã«ãªããŸãããæåã®èŠçŽ ã¯ 'f' ã«ãªããŸãã æ¬¡ã®äŸãèŠãŠã¿ãŸãããã
|
PHP 4 introduced the new curly bracket syntax to access characters in string, use this syntax instead of the one presented above:
|
ãã®ãããææ°ããŒãžã§ã³ã® PHP 3.0.12 ããã³ PHP 4.0b3-RC4 ã§ã¯ã ãã®èªå倿ã®çµæã¯æªå®çŸ©(undefined)ãšã¿ãªããŸãã ããããä¿®æ£æ¹æ³ãè°è«ãããŠããŸãã
|
Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast.
|
PHP ã®åãã£ã¹ãã¯ãC èšèªãšåæ§ã«åäœããŸããã€ãŸãã 倿ããããšããåã®?åããã£ã¹ããã倿°ã®åã«æ¬åŒ§ã«å
¥ã㊠眮ããŸãã
|
?php $foo = 10; / / $foo is an integer $bar = (boolean) $foo; / / $bar is a boolean?
|
䜿çšå¯èœãªãã£ã¹ãã以äžã«ç€ºããŸãã
|
(int), (integer) - cast to integer
|
(int), (integer) - æŽæ°ãžã®ãã£ã¹ã
|
(bool), (boolean) - cast to boolean
|
(bool), (boolean) - è«çå€ãžã®ãã£ã¹ã
|
(string) - cast to string
|
(float), (double), (real) - floatãžã®ãã£ã¹ã
|
(object) - cast to object
|
(string) - æååãžã®ãã£ã¹ã
|
Note that tabs and spaces are allowed inside the parentheses, so the following are functionally equivalent:
|
(array) - é
åãžã®ãã£ã¹ã
|
?php $foo = (int) $bar; $foo = (int) $bar;?
|
(object) - ãªããžã§ã¯ããžã®ãã£ã¹ã
|
Instead of casting a variable to string, you can also enclose the variable in double quotes.
|
æ³šæ æååã«å€æ°ããã£ã¹ããã代ããã«ã2éåŒçšç¬Šã§å€æ°ãæ¬ãããšã å¯èœã§ãã
|
?php $foo = 10; / / $foo is an integer $str = "$foo"; / / $str is a string $fst = (string) $foo; / / $fst is also a string / / This prints out that "they are the same "if ($fst === $str) {echo "they are the same";}?
|
æ¬åŒ§ã®äžã§ã¿ããšã¹ããŒã¹ã䜿çšããããšãã§ããããšã«æ³šæããŠãã ãããåŸã£ãŠãæ¬¡ã®æã¯ãæ©èœçã«ç䟡ã§ãã
|
For more info, see these sections:
|
åã®éã§ãã£ã¹ããè¡ãéã®åäœã¯ãå¿
ãããæç¢ºã§ã¯ãããŸããã詳 现ã«ã€ããŠã¯ã以äžã®ç¯ãåç
§äžããã
|
Converting to integer
|
è«çå€ãžã®å€æ
|
Converting to string
|
æŽæ°ãžã®å€æ
|
Converting to object
|
é
åããæååã«ãã£ã¹ããŸãã¯åŒ·å¶çãªå€æãè¡ã£ãå Žåãçµæã¯ã åèª Array ãšãªããŸãããªããžã§ã¯ãããæååã« ãã£ã¹ããŸãã¯åŒ·å¶çãªå€æãè¡ã£ãå Žåãçµæã¯ãåèª Object ãšãªããŸãã
|
Prev
|
ã¹ã«ã©ãŒãŸãã¯æåå倿°ããé
åã«ãã£ã¹ããè¡ãæã倿°ã¯é
åã® æåã®èŠçŽ ã«ãªããŸãã
|
Pseudo-types used in this documentation
|
ã¹ã«ã©ãŒãŸãã¯æåå倿°ãããªããžã§ã¯ãã«ãã£ã¹ããè¡ãæã倿° ã¯ãªããžã§Â¯ãã®å±æ§ã®äžã€ã«ãªããŸãããã®å±æ§ã®åå㯠'scalar' ã« ãªããŸãã
|
There are many ways to access this information, for example:
|
ãã©ãŒã ã PHP ã¹ã¯ãªããã«æçš¿ãããæããã©ãŒã ããæž¡ãããå
šãŠ ã®å€æ°ã¯ PHP ã«ããèªåçã«ã¹ã¯ãªãããã䜿çšå¯èœãšãªããŸãã ãã®æ
å ±ã«ã¢ã¯ã»ã¹ããææ®µã¯è€æ°ãããŸããäŸã以äžã«ç€ºããŸãã
|
A simple HTML form
|
äŸ 8-1ç°¡åãªHTMLãã©ãŒã
|
Depending on your particular setup and personal preferences, there are many ways to access data from your HTML forms.
|
ç¹å®ã®èšå®ãåå¥ã®èšå®ã«äŸåããHTMLãã©ãŒã ããã®ããŒã¿ã«ã¢ã¯ã»ã¹ ããææ®µã¯å€ããããŸããããã€ãã®äŸã以äžã«ç€ºããŸãã
|
Accessing data from a simple POST HTML form
|
äŸ 8-2ç°¡åãªPOST HTMLãã©ãŒã ããã®ããŒã¿ã«ã¢ã¯ã»ã¹ãã
|
As of / / PHP 4.2.0 the default value of register_globals = off. / / Using / relying on this method is not preferred. print $username;?
|
GETãã©ãŒã ã䜿çšããå Žåãåãã§ããããããã«é©åœãªå®çŸ©æžã¿ã® GET倿°ã䜿çšãããšãããç°ãªããŸãã GETã¯ãQUERY_STRING (URLã®'?'ã®åŸã®æ
å ±)ã«ã代å
¥ãããŸãã äŸãã°ã http://www.example.com/test.php?id=3 ã«ã¯ã $_GET['id'] ã«ããã¢ã¯ã»ã¹å¯èœãªGETããŒã¿ ãå«ãŸããŸãã $_REQUEST ããã³ import_request_variables() ãåç
§äžããã
|
GET also applies to the QUERY_STRING (the information after the '?' in an URL).
|
泚æ $_POST ããã³ $_GET ã®ãã㪠ã¹ãŒããŒã°ããŒãã« é
å ãPHP 4.1.0ã§å©çšå¯èœãšãªã£ãŠããŸãã
|
See also $_REQUEST and import_request_variables().
|
åèšã®ããã«PHP 4.2.0ããåã®ããŒãžã§ã³ã§ã¯ã register_globals ã®ããã©ã«ãå€ã¯ on ã§ããã PHP 3ã§ã¯ãåžžã«onãšãªã£ãŠããŸãã PHPã³ãã¥ããã£ã¯ããã®ãã£ã¬ã¯ãã£ãã«äŸåããªãããšãæšå¥šãã ãã®ãªãã·ã§ã³ã off ã§ã®ã³ãŒãã®åäœãä»®å® ããããšãæšå¥šããŠããŸãã
|
As shown, before PHP 4.2.0 the default value for register_globals was on.
|
泚æ magic_quotes_gpc ã®èšå® ã¯GETãPOSTãããŠCookieã®å€ã«åœ±é¿ããŸããonã«ãªã£ãŠãããš (It's "PHP!") ãšããå€ã¯èªåçã« (It\'s \"PHP!\") ãšãªããDBãžã®æ¿å
¥æã® ãšã¹ã±ãŒããäžèŠã«ãªããŸãã addslashes() ã stripslashes() ãã㊠magic_quotes_sybase ã åç
§ããŠãã ããã
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.