2013-12-10 41 views
0

我想使用str_replace te替换变量中的某些值,并获取名为$ username的值为USERNAME的变量。它适用于一个值,但不适用于多个值。str_replace多个字符串

该工程..

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

但是有四种可能性网址可怎么看,所以我需要4个变量

$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 
};