PHP 함수 get cwd depth()

Jmnote (토론 | 기여)님의 2015년 9월 1일 (화) 18:16 판 (새 문서: ==개요== ;PHP 함수 get_cwd_depth() * / 에서 현재작업디렉토리까지의 깊이를 알려주는 함수 <source lang='php'> function get_cwd_depth() { $cwd = getcwd(); if...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

PHP 함수 get_cwd_depth()
  • / 에서 현재작업디렉토리까지의 깊이를 알려주는 함수
function get_cwd_depth() {
	$cwd = getcwd();
	if( $cwd == '/' ) return 0;
	return count(explode('/',$cwd))-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 /
[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 }}