"PHP 함수 get cwd depth()"의 두 판 사이의 차이

잔글 (Jmnote 사용자가 PHP get cwd depth() 문서를 PHP 함수 get cwd depth() 문서로 옮겼습니다)
5번째 줄: 5번째 줄:
<source lang='php'>
<source lang='php'>
function get_cwd_depth() {
function get_cwd_depth() {
$cwd = getcwd();
return count(explode('/', getcwd()))-1;
if( $cwd == '/' ) return 0;
return count(explode('/',$cwd))-1;
}
}
</source>
</source>

2015년 9월 1일 (화) 18:26 판

1 개요

PHP 함수 get_cwd_depth()
  • / 에서 현재작업디렉토리까지의 깊이를 알려주는 함수
function get_cwd_depth() {
	return count(explode('/', getcwd()))-1;
}

2 실행예시

[root@zetawiki ~]# pwd
/root
[root@zetawiki ~]# cat get_cwd_depth.php 
<?php
function get_cwd_depth() {
	$cwd = getcwd();
	if( $cwd == '/' ) return 0;
	return count(explode('/',$cwd))-1;
}
echo get_cwd_depth()."\n";
[root@zetawiki ~]# php get_cwd_depth.php 
1
[root@zetawiki ~]# cd /
[root@zetawiki /]# php /root/get_cwd_depth.php 
0
[root@zetawiki /]# cd /var/www/html
[root@zetawiki html]# php /root/get_cwd_depth.php 
3

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}