473,385 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

using substr() with apostrophe in the string

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?

Jul 29 '05 #1
2 2881
la*****@gmail.com wrote:
What gives?


I'm guessing you have the apostrofe in its entity code

You can try and decode the string:

$word = html_entity_decode($word, ENT_QUOTES);
Jul 29 '05 #2

jamen wrote:
la*****@gmail.com wrote:
What gives?


I'm guessing you have the apostrofe in its entity code

You can try and decode the string:

$word = html_entity_decode($word, ENT_QUOTES);


That's exactly right! I was encoding the strings before they were
entered into the function. Thanks.

Jul 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andy | last post by:
I haven't done any web work for over a year and for the life of me I cannot remember how to use a query string in a URL. I want the link to be page.aspx?ID=1 then pass 1 into a query like this ...
2
by: JohnnySparkles | last post by:
Hi everyone, I'm currently writing an application which uses the XmlSerializer class to serialize/deserialize objects to/from xml. Now when deserializing an XmlDocument back into the object,...
2
by: pmatos | last post by:
Hi all, I'm trying to use a map of string* and unsigned ints but results are not good. I've used as example this piece of code: http://www.sgi.com/tech/stl/Map.html And I have done this:...
3
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the...
11
by: Martin Jørgensen | last post by:
Hi, - - - - - - - - - - - - - - - #include <iostream> #include <string> #include <map> using namespace std; int main() {
6
by: trevor | last post by:
Incorrect values when using float.Parse(string) I have discovered a problem with float.Parse(string) not getting values exactly correct in some circumstances(CSV file source) but in very similar...
4
by: moondaddy | last post by:
I need to edit the text in many files so I'm writing a small routine to do this. First I have a method that loops through all the files in a directory and passes the full file path to another...
4
by: crazy_jutt | last post by:
hi all, i heard that db2 ignores indexes when using any column function on the column which has index on it. but i have seen db2 using indexes even when using column function. what is the...
1
by: niteshpanchal | last post by:
Hi, How to assign dynamic array using pointers for string.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.