"Jim Carlock" previously asked:
Does PHP provide a function to extract the rightmost characters
from a string?
On Sun, 19 Feb 2006 21:32:19 -0500
"Shelly" <sh************@asap-consult.com> posted:
"Shelly" <sh************@asap-consult.com> commented: I think there is a function, but offhand can't recall it and a quick
search of www.php.net didn't reveal it quickly. However,
there is always:
$sStateAbbr = substr($sCityState, strlen($sCityState) - 2);
Hi, Shelly,
Thank you for your post. The function to use is substr(). If you
insert a negative number as the second parameter, it returns the
requested number of rightmost characters. I ran into the same
problem you ran into regarding the PHP.NET site, whereby
searching for "right characters" just fails to yield anything
quickly.
I had already found the answer when I posted. The reason
for asking was two fold. (1) To see what kind of other answers
might turn up. (2) "The power of suggestion."
The second goal provides a hint to others.
Rather than allowing everyone to guess at what I'm suggesting,
I'm going to lay it out straight and true...
The following keywords would be helpful for finding the answer
to the question asked, in other words, the keywords should be
applied to the bottom of the page and to the META keyword list.
right$, rightmost, right most characters, right characters, trailing
character extraction, final character extraction
Maybe someone at php.net will read and give some consideration to
the idea. If anyone else reads this and feels its a worthwhile
investment, or if they know how to contact anyone that works for
the organization, feel free to pass the idea on. I'd be willing to
invest an hour a night into adding keywords. Let the folks at
PHP.NET know.
And giving this some thought, for the following function,
is there another way to write it or another suggestion?
function ExtractConditionCategory() {
if (isset($_GET['switch'])) {
return('switch');
} elseif (isset($_GET['if'])) {
return('if');
} elseif (isset($_GET['while'])) {
return('while');
} elseif (isset($_GET['for'])) {
return('for');
} elseif (isset($_GET['foreach'])) {
return('foreach');
} else {
// default to do-while
return('do-while');
}
}
Thanks much.
Jim Carlock
Post replies to the newsgroup.