2013-12-10 2 views
0

str_replace te를 사용하여 변수의 일부 값을 바꾸고 USERNAME 값의 $ username 변수를 가져 오려고합니다. 그것은 한 값에 대해서는 잘 작동하지만 여러 값에 대해서는 작동하지 않습니다.str_replace multiple strings

이 작동 ..

$myabsoluteurl=JURI::current(); 
$replacestring='http://www.website.com/index.php/component/comprofiler/userprofile/'; 
$usertemp= str_replace($replacestring, '', $myabsoluteurl); 

그러나 그래서 난 4 개 변수

을 필요 URL을 볼 수있는 방법을 네 가지 가능성이 있습니다
$replacestring1='http://www.website.com/index.php/component/comprofiler/userprofile/'; 
$replacestring2='http://www.website.com/index.php/instellingen/userprofile/'; 
$replacestring3='http://www.website.com/index.php/component/comprofiler/'; 
$replacestring4='http://www.website.com/index.php/instellingen'; 

등 네 가지 가능성이 그래서 난 나머지를 배치 할 수 있습니다 스트립 핑 얻을 수있는 방법 변수의 값? 사용자 이름은 항상 네 개의 URL 중 하나 뒤에 배치됩니다.

답변

0

$replacestring을 배열로 선언 한 다음 배열 내에서 for 루프를 실행할 수 있습니다.

$replacestring = array('string1', 'string2'); 
foreach ($replacestring as $string) { 
    // do stuff 
};