ȥå   Խ ʬ Хåå ź ʣ ̾ѹ   ñ측 ǽ   إ   ǽRSS

PHP/ʸˡ

Last-modified: 2012-02-20 () 04:24:26 (2104d)
Top / PHP / ʸˡ

PHP

ܾ

ĥ.php

ȵˡ

  • //
  • #
  • /* */

: //, #ϡޤ?>ޤǤȤˤʤޤ

print, echo

  • echo, print˸칽¤ʤΤ()̵Ƥ⵭ҤǤޤ
  • echoϥޤǶڤäϢϤǤޤ
  • ŰǰϤѿŸ䥨ץ󥹤򵭽ҤǤޤ${}Ȥ̤ǰϤѿǤ뤳ȤΤˤʤޤ
echo $a, $b;
print "Hello ${name}\n"

integer100, 0xff
booleanTRUE, FALSE
float3.14, 1.2e3
string'yes', "Hello!\n"
arrayarray('red', 'blue', 'green')
  • gettype($ѿ̾)Ƿ̾ʸ󤬼Ǥޤgettype(3.14)double֤ޤjavaǤȤfloatƱͤΰ̣Ǥ
  • åȤis_int($var)is_string($var)ʤɤѤޤ
  • (̾)ǥ㥹ȤǤޤ
  • ѿؿͤηϤޤ

ˡ

define("NAME", value);

Ѥ

̣̾
NULL̤ɽ͡ʸnullȤޤ
FALSE
TRUE
__FILE__¹ԤƤ륹ץȥե̾
__LINE__¹ԤƤֹ

ջࡧunset(ѿ̾);ȤѿΤΤ̵ʤޤNULLѿϤʤʤ餺̤Ȥ֤¸ߤޤ

ѿ

PHPѤѿ

̾
$_SERVER['argv']ץȤϤ
$_SERVER['argc']ץȤϤο
$_SERVER['PHP_SELF']ɥȥ롼ȤȤץȤХѥ

ApacheͳѤѿ

̾
$_SERVER['DOCUMENT_ROOT']ɥȥ롼ȥǥ쥯ȥ
$_SERVER['HTTP_USER_AGENT']
$_SERVER['REMOTE_ADDR']饤ȤIPɥ쥹
$_SERVER['REMOTE_PORT']饤ȤΥݡֹ
$_SERVER['SCRIPT_FILENAME']ץȤХѥ
$_SERVER['SCRIPT_NAME']ץȤХѥ
$_SERVER['SERVER_NAME']ФΥۥ̾
$_SERVER['SERVER_PORT']ФΥݡֹ
$_SERVER['SERVER_PROTOCOL']ץȥ̾ȥС

ѿ

$foo = 7;
$varX = "foo";
print($$varX); // 7

󡦥ϥå

ˡ

$arColor = array(
    'red',
    'green',
    'blue');
$arColor = array();
$arColor[] = 'red';
$arColor[] = 'green';
$arColor[] = 'blue';
$arColor = array(
    0=>'red',
    1=>'green',
    2=>'blue');
$arColor = array();
$arColor[0] = 'red';
$arColor[1] = 'green';
$arColor[2] = 'blue';
  • print_r($arColor);dzǧǤޤ
    Array ( [0] => red [1] => green [2] => blue )

Ŀꤷƽˡ

$arColor = array();
$arColor = array_pad($arData, 3, 'white'); // 󡢳ĥĿ

ջ

$sum_data[] = array();
$sum_data = array();

$sum_data[] = array(0, 0, 0, 0, 0, 0, 0);
$sum_data = array(0, 0, 0, 0, 0, 0, 0);

ɽϡǤ¸ߤ$sum_dataؤpushȤʤޤ
$sum_data[] = array(0, 0, 0, 0, 0, 0, 0);

ϥåˡ

$arColor = array(
    'red'=>'#ff0000',
    'green'=>'#00ff00',
    'blue'=>'#0000ff');
$arColor['red'] = '#ff0000';
$arColor['green'] = '#00ff00';
$arColor['blue'] = '#0000ff';
  • print_r($arColor);dzǧǤޤ
    Array ( [red] => #ff0000 [green] => #00ff00 [blue] => #0000ff )

Ǥκ󥤥ǥåľˡ

$a = array(1 => 'one', 2 => 'two', 3 => 'three');
unset($a[2]);
$b = array_values($a); // bϡarray(0 => 'one', 1 =>'three')Ȥʤޤ

ͤFALSEȤʤޤ

  • integer0
  • double0.0
  • ʸ ʸ"0"
  • ǤοǤ
  • ǤȤ륪֥(PHP 4Τ)
  • ̤ NULL(ͤåȤƤʤѿޤ)
  • Υ줿 SimpleXML ֥

dzä硢floatͤȤʤޤ

ʸ黻

ԥꥪɤʸη礬Ԥޤ

print("foo"."99");
$strTmp .= "123";

¹Ա黻

ХåȤǥޥɤϤȡμ¹Է̤ʸȤƼǤޤ

<?php
    $strTmp = `pwd`;
    print("<pre>".$strTmp."<pre>");
?>

顼黻

@ؿƬդȡ顼åϤʤʤޤ

$fin = @fopen("foo.txt", "r") or die("ե뤬¸ߤޤ");

ʸ

ץ󥹰

\xnn16ʿɽΣʸ
\rå꥿, CR, 0x0d
\n, LF, 0x0a
\tʿ
\$ɥ뵭, PHPǤŰʸѿŸǤޤ
\"Ű
\\\, ŰʸǤѲǽ
\'Ű, Űʸǻ

ҥɥ

$str = <<< HERE
ҤȤҤȤ
ҤȤߤ
HERE;
print("<pre>".$str."<pre>");

ҥɥȤϥѡޤ

湽¤

if, switch, while, do while, forʸϡjavaƱǤ

$arColor = array(
    'red'=>'#ff0000',
    'green'=>'#00ff00',
    'blue'=>'#0000ff');
foreach ($arColor as $value) {
    print($value."<br />");
}
foreach ($arColor as $key => $value) {
    print($key."<br />");
}

ؿ

$g_charForPrint = '*';
function printChars($iCount) {
    global $g_charForPrint;
    for ($i = 0; $i < $iCount; $i++) {
        print($g_charForPrint);
    }
}
printChars(10);

饤֥ꡦ󥯥롼ɥե