Ok, so I'm used to string manipulation in ASP (with right and left) but I'm a bit perplexed with PHP. So here's the situation...my parents went away on a ...ok sorry. Here is what I have: I'm working on a custom login redirect for an existing training cms (sounds like Poodle) and having problems. I have a user go to this url: /login/index.php?client=FredsDOG and login with the following: username: chuckABC password: whatever in the login code, I construct the username this way: $normalUser=$frm->username.'||'.$frm->client; So now, $normalUser = chuckABC||FredsDOG BUT, I want to check if the username has a three digit code tacked at the end of the username and do some manipulation, so: If username ends in ABC, then I want to do this $normalUser = fredsABC||ABC instead of $normalUser = chuckABC||FredsDOG in asp, i would just take the string, 4 spaces to the left and beyond...but not sure how to do this in PHP. Any ideas?
I don't quite understand what you mean by the manipulation from one to the other, but take a look at the substr() function. Pretty sure that is what you want
substr() looks like the way to go! So, how do I use it if I want to hack off or snag the last three character of a string...like this: $rest = substr("dogABC", ?); I would like $rest to return "dog", I would like the assign the characters "ABC" to another variable...like $affix for instance.
From what I understood, you want to get the last three digits after || in the username? JAY6390 was right, you'll want to use substr(); <?php echo substr('fredsABC||ABC', -3, 3); ?> PHP: Will print out: ABC Just replace the string with the variable containing the username. Regards, Steve
Awesome. This works for me. Thanks for the help. For me I just wanted to snag the 3 characters before the ||, but this makes sense though. Thanks the for explanation. This is what worked for me: echo substr('fredsABC||ABC', -8, 3); However if the length of the right ABC changes, I may be up a creek... I guess what I really should do is find the first instance of || and grab the left 3. I'll figure it out Thanks again guys!
In that case, it may be better to use explode() $stuff = explode('||', 'fredsABC||ABC'); $stuff[0] will contain fredsABC (the first part) and $stuff[1] will contain ABC (the second part) That way it doesn't matter how long they are in length it'll just use the || as a delimiter. Regards, Steve