PHP ãã¢ããã¥ã¡ã³ãã®ä½¿ãæ¹ï¼2éã
PHPã§ã®ãã¢ããã¥ã¡ã³ãã®ä½¿ãæ¹â¦ã
è·æ¥è¨ç·´ã®è¬ç¾©ã§æãã£ãã®ã¯
1 : print ã echo ã§ä½¿ã
ã¨ãããã®ã§ããã
print <<< EOFãè¤æ°è¡ã®æãç´æ¥è¨è¿°ã
$hoge âå¤æ°ã¯å±éãããEOF;
ã¦ã£ããããprintãããechoãã¨ã»ããã§ãã使ããªãã®ãã¨
æã£ã¦ã¾ããããå¤æ°å
ã§ä½¿ããã¨ãã§ããããã§â¦ã
2 : å¤æ°å ã§ä½¿ã
$name = 'ç°ä¸';
$sex = 'ç·';$hoge = <<< EOF
<p>
ç§ã®åå㯠$name ã§ãã<br>
ç§ã®æ§å¥ã¯ $sex ã§ãã
</p>
EOF;echo $hoge;
ã¨ããã§ã以åã¯ããã¢ããã¥ã¡ã³ãå
ã§ã¯é
åããªãã¸ã§ã¯ãã®ã¡ã³ãå¤æ°ã¯
使ããªããã®ã¨åéããã¦ããããã
- å¤æ°ã«ä»£å ¥ãã¦ãã使ã
- ä¸æçã«ãã¢ããã¥ã¡ã³ããä¸æãã
- ãprintf()ãã使ã
æãã¦ããã ãã¾ããã
3 : é åããã¡ã³ãå¤æ°ãå±éãããã
Akazaãããã©ãããããã¨ããããã¾ãããm(_ _)m
$hoge = <<< eof
<p>
ç§ã®åå㯠{$obj->name} ã§ãã<br>
ç§ã®æ§å¥ã¯ {$sex[0]} ã§ãã
</p>
eof;
//ãªããé常ã®ããã«ã¯ã©ã¼ãã¼ã·ã§ã³ã§å²ã¾ããæååã§ãåãã§ãã
$piyo = "ç§ã®åºèº«ã¯ {$prefecture[24]} ã§ãã";
ã¡ãªã¿ã«â¦ã
4 : printf()ã使ãæ¹æ³
ã3ãã¨æ¯ã¹ã¦ãããããããããªâ¦ãããã«ãããããªâ¦ï¼
$hoge = <<< eof
<p>
ç§ã®åå㯠%s ã§ãã<br>
ç§ã®å¹´é½¢ã¯ %d ã§ãã
</p>
eof;
printf($hoge, $obj->name, $obj->age);
è¿½è¨ 2012-09-08
ã©ãã§ããããã¨ã§ãããç§ã¯ãã¢ããã¥ã¡ã³ãã®çµäºã®èå¥åã®å¾ã®ã»ãã³ãã³(;)ã¯å¿ é ã ã¨åéããã¦ãã¾ãããããããããã»ãã³ãã³ã¯ç¹ä¾ã¨ãã¦èå¥åã®å¾ã«ã¤ãããã¨ã許ããã¦ããã®ã ããã§ãã
ã¤ã¾ããæ¬æ¥ã¯ããããã¹ããªã®ã ããã§ãã
èå¥åã¨ã»ãã³ãã³ã¨ã¯ãä½ã®é¢é£ããªãã¨ãããã¨ã§ããã
$hoge = <<< EOF
abcd
efgh
ijkl
EOF
;
ãããªãã¨ãä»æ¥ã¡ãã£ã¨ã¤ã¾ã¥ãããã¨ã®åå ãããåããã¾ããã
é£æ³é åã®å¤ããã¢ããã¥ã¡ã³ãã§è¨è¿°ãããã¨ããã³ã¼ãã
çµäºã®èå¥åã®å¾ã«ã»ãã³ãã³ãã¤ããããã¨ã©ã¼ã«ãªã£ã¡ããã¾ãããâ¦(^ ^;)
(CakePHP)
echo $this->Form->textarea('tags', array(
'rows' => 8,
'cols' =>40,
'value'=> <<< EOF
abcd
efgh
ijkl
EOF
));
ç§ã®ææãã¦ãããªã©ã¤ãªã¼æ¬ã®ãããã°ã©ãã³ã°PHP 第2çãã«ã¯ãã»ãã³ãã³ã®ç¹ä¾ã«ã¤ãã¦ãã¡ãã¨æ¸ããã¦ãã¾ããã
ãã¿ãããã¾ããã¼ m(_ _)m