2010-03-11 5 views

답변

0

글쎄, 당신은 당신이 버려야 할 경로의 부분이 무엇인지 알고 있다면, 당신은 단순히 않는 str_replace 할 수있는 :

$dbc_root = str_replace('/home/USER/', '', $dbc_root); 
3

난 당신이 경로와 관련된 방법을 확인해야한다고 생각 :

pathinfo() - Returns information about a file path 
dirname() - Returns directory name component of path 
basename() - Returns filename component of path 

이러한 솔루션 중 하나를 찾을 수 있어야합니다.

+0

에서 제거 된 텍스트는이 늘 작품 두 개 이상의 directori이있는 경우 위의 'USER' 디렉토리를 찾습니다. –

1

형식이 고정 된 방식에 따라 다릅니다. 당신이 public_html 후 모든 것을 얻을해야하는 경우

$dbc_root = str_replace('/home/USER', '', getcwd()); 

은 : 쉬운 형태

preg_match('/public_html.*$/', getcwd(), $match); 
$dbc_root = $match; 
+0

감사합니다. :) – Adrian

0

당신은 빈 문자열로 /home/USER을 대체 할 수

$path=str_replace("/home/USER", "", getcwd()); 
1
<?php 
function pieces($p, $offset, $length = null) 
{ 
    if ($offset >= 0) $offset++; // to adjust for the leading/
    return implode('/', array_slice(explode('/', $p), $offset, $length)); 
} 

echo pieces('/a/b/c/d', 0, 1); // 'a' 
echo pieces('/a/b/c/d', 0, 2); // 'a/b' 
echo pieces('/a/b/c/d', -2); // 'c/d' 
echo pieces('/a/b/c/d', -2, 1); // 'c' 
?> 
0
$dbc_root = getcwd(); // That will return let's say "/home/USER/public_html/test2" 
    $dbc_root .= str_replace('/home/USER', '', $dbc_root); // Remember to replace USER with the correct username in your file ;-) 

이후 당신의 $dbc_root 집/USER /없이해야한다이의 새로운 VAR를 생성하고 싶은 경우 나, 테스트하지 않았다

은 ... 당신이 시도 할 수 :

$slim_dbc_root = str_replace('/home/USER', '', $dbc_root); 

을 나는이 도움이되기를 바랍니다 올바른 방향

0

에 당신은 시도이 "/ 홈/pophub/public_html을 /"당신이에 getcwd()

$dir = getcwd(); 
$dir1 = str_replace('/home/pophub/public_html/', '/', $dir); 
echo $dir1; 
관련 문제