Hey folks -
I'm working on a spellchecking routine. The pspell libraries don't
handle punctuation; I have to make a script a little smarter.
I'm having a problem popping English posessive endings off of strings.
I thought that this little snipper would do the job:
<code>
if ( substr( $word, -2) == "\'s" ) {
$word = substr($word, -2);
}
</code>
But it doesn't. I wrote some test code, and it seems that PHP or Apache
or something is parsing the apostrophe as something else, at least for
a few characters. See what mean ( p() is a function that encapsulates a
string in <P> </P> tags):
<code>
echo p( $word . " " . substr($word, -1) );
echo p( $word . " " . substr($word, -2) );
echo p( $word . " " . substr($word, -3) );
echo p( $word . " " . substr($word, -4) );
echo p( $word . " " . substr($word, -5) );
echo p( $word . " " . substr($word, -6) );
echo p( $word . " " . substr($word, -7) );
echo p( $word . " " . substr($word, -8) );
</code>
<output>
guest's s
guest's ;s
guest's 9;s
guest's 39;s
guest's 039;s
guest's #039;s
guest's 's
</output>
So it would seem that
<code>
substr( $word, -7)
</code>
should return 's , but it doesn't. Or, at least, the following does not
do the job:
<code>
if ( substr( $word, -7) == "\'s" ) {
$word = substr($word, -7);
}
</code>
What gives?