~~Title:PHP 복붙용 코드 모음~~
public function &argsArray() { static $flags = Array(); return $this->flags; }
<?php // 테스트 웹 서버가 iis7 이고 // http://127.0.0.1/ppp/z/ 가 웹 주소이고 // c:\inetpub\wwwroot\ppp\z 가 설치 위치인 경우 (c:\inetpub\wwwroot : 웹서버 문서 루트 폴더) if( !defined('MYDOC_ROOT') ) { define( 'MYDOC_ROOT', dirname(__FILE__) ); } if( !defined('MYSITE_DIR') ) { define( 'MYSITE_DIR', dirname($_SERVER['PHP_SELF']) ); } if( !defined('MYWWW_ROOT') ) { define( 'MYWWW_ROOT', 'http://'.$_SERVER['SERVER_NAME'].MYSITE_DIR ); } echo MYDOC_ROOT . '</br>'; // c:\inetpub\wwwroot\ppp\z echo MYSITE_DIR . '</br>'; // /ppp/z echo MYWWW_ROOT . '</br>'; // http://127.0.0.1/ppp/z ?>
기본
<?php function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs<br />\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "Argument $i is: " . $arg_list[$i] . "<br />\n"; } } foo(1, 2, 3); ?>
활용
//test.php <?php function foo() { include './fga.inc'; } foo('First arg', 'Second arg'); ?> //fga.inc <?php $args = func_get_args(); var_export($args); ?>
$sampleXmlString2 = 'help me'; //$gzEncodeData = gzcompress($sampleXmlString, 9); $gzEncodeData = gzencode($sampleXmlString, 9); echo '\n' . bin2hex($gzEncodeData) . '\n'; //$gzDecodeData = gzuncompress($sampleXmlString, 9); $gzDecodeData = gzdecode( $gzEncodeData ); echo '\n' . $gzDecodeData . '\n';
// 샘플 xml $sampleXmlString = <<<XML <?xml version="1.0" encoding="UTF-8"?> <aracomm pktversion="1"> <header> <packet index="1" subindex="333"/> <desc>login</desc> </header> <data direction="send"> <var name="id" value="testMyIdIsXXXX" /> <var name="pw" value="passwordpassword" /> </data> </aracomm> XML;
// 메모리에서 바로 읽어들이기 $xmlObj = simplexml_load_string($sampleXmlString); // Basic SimpleXML usage (여기) // 여러가지 데이터 읽어보기 $xmlObj = simplexml_load_string($sampleXmlString); print_r( $xmlObj ); // xml 전부 덤프 //$arrXml = objectsIntoArray($xmlObj); print_r( $xmlObj['pktversion'] ); print_r( $xmlObj->header->packet['index'] ); echo 'packet index ' . $xmlObj->header->packet['index']; print_r( $xmlObj->data->var['value'] ); print_r( $xmlObj->data->var['value'] );