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

잔글 (Jmnote 사용자가 PHP get cwd depth() 문서를 PHP 함수 get cwd depth() 문서로 옮겼습니다)
잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 3개는 보이지 않습니다)
3번째 줄: 3번째 줄:
* / 에서 현재작업디렉토리까지의 깊이를 알려주는 함수
* / 에서 현재작업디렉토리까지의 깊이를 알려주는 함수


<source lang='php'>
<syntaxhighlight 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>
</syntaxhighlight>


==실행예시==
==실행예시==
<source lang='cli'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# pwd
[root@zetawiki ~]# pwd
/root
/root
</source>
</syntaxhighlight>
<source lang='cli'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cat get_cwd_depth.php  
[root@zetawiki ~]# cat get_cwd_depth.php  
<?php
<?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;
}
}
echo get_cwd_depth()."\n";
echo get_cwd_depth()."\n";
</source>
</syntaxhighlight>
<source lang='cli'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# php get_cwd_depth.php  
[root@zetawiki ~]# php get_cwd_depth.php  
1
1
</source>
</syntaxhighlight>
<source lang='cli'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cd /
[root@zetawiki ~]# cd /
[root@zetawiki /]# php /root/get_cwd_depth.php  
[root@zetawiki /]# php /root/get_cwd_depth.php  
0
0
</source>
</syntaxhighlight>
<source lang='cli'>
<syntaxhighlight lang='console'>
[root@zetawiki /]# cd /var/www/html
[root@zetawiki /]# cd /var/www/html
[root@zetawiki html]# php /root/get_cwd_depth.php  
[root@zetawiki html]# php /root/get_cwd_depth.php  
3
3
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:35 기준 최신판

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() {
	return count(explode('/', getcwd()))-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 }}