 |
|
|  |
| [php] 주석과 공백을 제거하여 반환하는 php strip whitespace 함수 |
|
|
 |
12년 전 |
string php_strip_whitespace ( string $filename ) (PHP 5)
php 파일내 주석과 공백을 제거한 소스를 반환하는 함수입니다.
예제(ex #1
<?php
// PHP comment here
/*
* Another PHP comment
*/
echo php_strip_whitespace(__FILE__);
// Newlines are considered whitespace, and are removed too:
do_nothing();
/* 결과: <?php
echo php_strip_whitespace(__FILE__); do_nothing(); ?>
*/
?>
예제(ex #2
<?php
echo php_strip_whitespace(__FILE__);
/**
* @author Zulfugar Ismayilzadeh
* @copyright 2011
*/
function count_words($string){
$string = trim(preg_replace("/\s+/"," ",$string));
$word_array = explode(" ", $string);
$num = count($word_array);
return $num;
}
$str = "Hello fri3nd, you're looking good today!";
echo count_words($str);
/* 결과: <?php
echo php_strip_whitespace(__FILE__); function
count_words($string){ $string = trim(preg_replace("/\s+/"," ",
$string)); $word_array = explode(" ", $string); $num = count $word_array); return
$num; } $str = "Hello fri3nd, you're looking good today!";
echo count_words($str); ?>
*/
?>
주석, 공백을 제거한 php 소스를 새로운 파일에 작성해 보겠습니다. 이렇게 따로 작성해서 배포를 해두면 일반 사용자가 읽기에 어려움이 있어 약간의 보안(?)성이 생기게 됩니다.
예제(ex #3
<?php
$fp = fopen('oldfile.php', 'w+');
$tmp = php_strip_whitespace('newfile.php');
fputs($fp, $tmp);
fclose();
?>
|
|
추천 : 650 |
추천
목록
|
|
|  |
|