Reputation: 853
Some of my users log into the system using the domain name, so if the domain is "theHub", the type in thehub\j51289 as their username.
The username ends in a session variable called username, however I need to remove the domain name from the username if it exists.
I've found substr function to work up until the \ character - and then it fails. I know that it is an escape character, but can't figure out how to implement it in my code, can anyone help?
if(substr(strtoupper($_SESSION['username']), 0, 7 ) === "THEHUB\")
{ echo "it has found it";
$_SESSION['username'] = str_replace(strtoupper("THEHUB\"", "", $_SESSION['username']));
}
else
{ echo "no it has not found it";}
Upvotes: 0
Views: 49
Reputation: 32028
You should escape backslash \
with another backslash : \\
like this : "THEHUB\\"
(You can have a look here : http://php.net/manual/en/language.types.string.php)
Upvotes: 0
Reputation: 349
Use addslashs to escape the string. https://www.php.net/addslashes
Upvotes: 0
Reputation: 169143
You need to escape the backslash with another backslash. For example:
echo "foo\\bar";
Will display the following:
foo\bar
In this case it sounds like you want to use "THEHUB\\"
.
Upvotes: 2