Gossamer Forum
Home : General : Perl Programming :

Remove <'s> from a string

Quote Reply
Remove <'s> from a string
Hi,

I'm using the contents of the $query string in LinksSQL to push keywords into my ad-script call, but any time someone uses 's is their search query, the ' breaks the sql statement and reports an error in the server log. Will this remove 's from the query?

$adkeywords =~ s/'s//

E.g.; Penny's -> Penny, Athlete's Foot -> Athlete Foot, Women's Garments -> Women Garments

All the best
Shaun

Quote Reply
Re: Remove <'s> from a string In reply to
You should use the following:

Code:

$adkeywords =~ s/'s//g;


Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Remove <'s> from a string In reply to
Thanks Eliot, I wasn't sure of the exact syntax Smile

All the best
Shaun

Quote Reply
Re: Remove <'s> from a string In reply to
You're welcome.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: Remove <'s> from a string In reply to
why aren't you just escapeing the quotes?
the DBD::mysql module has a built in method called 'quote' of all things that will do this for you.

perldoc DBD::mysql
otherwise just use

$string =~ s/'s/\\'s/g;

no need to deform what people have submitted.

-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Remove <'s> from a string In reply to
GClemmons,

Sorry, I maybe didn't make it clear above, but I'm not actually changing the persons query.

I'm copying $query to $adkeywords so I can push ads based on the search words used. Unfotunately the ad-serving script's SQL call fudges when there's a 's in the string, so I'm removing them from the ad-script keyword string, as opposed to the actual search query Smile

All the best
Shaun

Quote Reply
Re: Remove <'s> from a string In reply to
Hi,

But it would probably break if someone entered can't as the search term. You need to escape single quotes (the ad program should really be doing this, as otherwise it's a bit of a security hole).

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Remove <'s> from a string In reply to
Alex,

Thanks ... I never even thought about 't ... ooppss Smile

I think I'll have a word with the ad software guy and see if he can't just fix the query line/string, that'll probably be the best all-round solution.

Thanks again.
Shaun

Quote Reply
Re: Remove <'s> from a string In reply to
How bout: '; DELETE FROM Links; as the search term. =)

(won't work in Mysql, but should frighten you enough to realize things should be quoted as there are similiar things you can do).

Cheers,

Alex

--
Gossamer Threads Inc.