leachus2002 Posted April 22, 2010 Share Posted April 22, 2010 Hi There, I am developing an internal web page on our intranet - and I am using the $_SERVER['REMOTE_USER'] varible to pass through who is logged on to a particular web page. Unfortunaetly, if I echo this on to the screen, it displays "domainname/username" - is there any way that I can remove the "domainname/" from the start of the string so that it just echo's "username"? Help appreciated Thanks Matt Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/ Share on other sites More sharing options...
oni-kun Posted April 22, 2010 Share Posted April 22, 2010 str_replace: $result = "domainname/username"; $username = str_replace("domainname/", "", $result); print $username; explode (preferred) $result = "domainname/username"; $username = explode("/", $result); print $username[1]; Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046336 Share on other sites More sharing options...
leachus2002 Posted April 22, 2010 Author Share Posted April 22, 2010 Thanks for coming back to me, however, I think I am getting confused: Where I am using the "$_SERVER['REMOTE_USER']" varible, would i have to code the following: $result = " $_SERVER['REMOTE_USER']"; $username = explode("/", $result); print $username[1]; Because the user will always be different Thanks Matt Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046343 Share on other sites More sharing options...
oni-kun Posted April 22, 2010 Share Posted April 22, 2010 Almost, This should work: $result = $_SERVER['REMOTE_USER']; $username = explode("/", $result); print $username[1]; Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046345 Share on other sites More sharing options...
leachus2002 Posted April 22, 2010 Author Share Posted April 22, 2010 Hi, Doesnt look like it I am afraid - I am just getting blank on both print $username[1] and I even tried echo $username. But if I echo $_SERVER['REMOTE_USER'] - I get domainname\username Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046352 Share on other sites More sharing options...
oni-kun Posted April 22, 2010 Share Posted April 22, 2010 The slash is reversed, as you see. That is simple to amend. $result = $_SERVER['REMOTE_USER']; $username = explode("\\", $result); print $username[1]; [ot]no salathe it doesn't need regex.[/ot] Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046354 Share on other sites More sharing options...
leachus2002 Posted April 22, 2010 Author Share Posted April 22, 2010 Ah totally pefect! Sorry that was my mistake initially! Brilliant work - thank you! Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046355 Share on other sites More sharing options...
leachus2002 Posted April 22, 2010 Author Share Posted April 22, 2010 Sorry to be a pain - but is there any way I can get that print line in to a varible? I have tried $user = print username[1]; echo $user - but that will echo username1 Thanks Matt Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046358 Share on other sites More sharing options...
oni-kun Posted April 22, 2010 Share Posted April 22, 2010 Sorry to be a pain - but is there any way I can get that print line in to a varible? I have tried $user = print username[1]; echo $user - but that will echo username1 Thanks Matt You'd need to do echo $username[1]. Echo and print are pretty much the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/199367-replace-text-using-php/#findComment-1046393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.