Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:30 AM
Ralph Freshour
Guest
 
Posts: n/a
Default Stripping Data Help Needed

I'm taking text from a textarea object and want to strip out
characters other than A-Za-z0-9 before I send the data to MySQL table
- is there a function I can use to do this in PHP?

Thanks...

  #2  
Old July 17th, 2005, 01:30 AM
Tom Thackrey
Guest
 
Posts: n/a
Default Re: Stripping Data Help Needed


On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
[color=blue]
> I'm taking text from a textarea object and want to strip out
> characters other than A-Za-z0-9 before I send the data to MySQL table
> - is there a function I can use to do this in PHP?[/color]

$strippedtext = preg_replace('/[^0-9a-z]/i','',$originaltext);

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
  #3  
Old July 17th, 2005, 01:30 AM
Ralph Freshour
Guest
 
Posts: n/a
Default Re: Stripping Data Help Needed

How would I handle special characters like single and double quotes?
forward and backward slashes?

Thanks...

On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey"
<use.signature@nospam.com> wrote:
[color=blue]
>
>On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
>[color=green]
>> I'm taking text from a textarea object and want to strip out
>> characters other than A-Za-z0-9 before I send the data to MySQL table
>> - is there a function I can use to do this in PHP?[/color]
>
>$strippedtext = preg_replace('/[^0-9a-z]/i','',$originaltext);[/color]

  #4  
Old July 17th, 2005, 01:30 AM
Tom Thackrey
Guest
 
Posts: n/a
Default Re: Stripping Data Help Needed


On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
[color=blue]
> On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey"
> <use.signature@nospam.com> wrote:
>[color=green]
> >
> >On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
> >[color=darkred]
> >> I'm taking text from a textarea object and want to strip out
> >> characters other than A-Za-z0-9 before I send the data to MySQL table
> >> - is there a function I can use to do this in PHP?[/color]
> >
> >$strippedtext = preg_replace('/[^0-9a-z]/i','',$originaltext);[/color][/color]
[color=blue]
> How would I handle special characters like single and double quotes?
> forward and backward slashes?
>[/color]

That will strip them out, too. It will remove everything but letters and
numbers from the original string. What the regular expression says is
replace every occurance of a character that is not (^) a number (0-9) or a
letter (a-z) both upper and lower case (i) with a null ('').

If you want to just make the string mysql safe but keep the punctuation use
addslashes().

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
  #5  
Old July 17th, 2005, 01:30 AM
Ralph Freshour
Guest
 
Posts: n/a
Default Re: Stripping Data Help Needed

I'm sorry I didn't think this through further Tom - while I wanted
initially 0-9a-z etc., after using this in a form (it worked really
neat!!), I realized that I needed to allow additional specific
characters such as {}[]<>

Ralph

On Mon, 13 Oct 2003 02:30:14 GMT, "Tom Thackrey"
<use.signature@nospam.com> wrote:
[color=blue]
>
>On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
>[color=green]
>> On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey"
>> <use.signature@nospam.com> wrote:
>>[color=darkred]
>> >
>> >On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
>> >
>> >> I'm taking text from a textarea object and want to strip out
>> >> characters other than A-Za-z0-9 before I send the data to MySQL table
>> >> - is there a function I can use to do this in PHP?
>> >
>> >$strippedtext = preg_replace('/[^0-9a-z]/i','',$originaltext);[/color][/color]
>[color=green]
>> How would I handle special characters like single and double quotes?
>> forward and backward slashes?
>>[/color]
>
>That will strip them out, too. It will remove everything but letters and
>numbers from the original string. What the regular expression says is
>replace every occurance of a character that is not (^) a number (0-9) or a
>letter (a-z) both upper and lower case (i) with a null ('').
>
>If you want to just make the string mysql safe but keep the punctuation use
>addslashes().[/color]

  #6  
Old July 17th, 2005, 01:31 AM
Tom Thackrey
Guest
 
Posts: n/a
Default Re: Stripping Data Help Needed


On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
[color=blue]
> On Mon, 13 Oct 2003 02:30:14 GMT, "Tom Thackrey"
> <use.signature@nospam.com> wrote:
>[color=green]
> >
> >On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
> >[color=darkred]
> >> On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey"
> >> <use.signature@nospam.com> wrote:
> >>
> >> >
> >> >On 12-Oct-2003, Ralph Freshour <ralph@primemail.com> wrote:
> >> >
> >> >> I'm taking text from a textarea object and want to strip out
> >> >> characters other than A-Za-z0-9 before I send the data to MySQL
> >> >> table
> >> >> - is there a function I can use to do this in PHP?
> >> >
> >> >$strippedtext = preg_replace('/[^0-9a-z]/i','',$originaltext);[/color]
> >[color=darkred]
> >> How would I handle special characters like single and double quotes?
> >> forward and backward slashes?
> >>[/color]
> >
> >That will strip them out, too. It will remove everything but letters and
> >numbers from the original string. What the regular expression says is
> >replace every occurance of a character that is not (^) a number (0-9) or
> >a
> >letter (a-z) both upper and lower case (i) with a null ('').
> >
> >If you want to just make the string mysql safe but keep the punctuation
> >use
> >addslashes().[/color][/color]
[color=blue]
> I'm sorry I didn't think this through further Tom - while I wanted
> initially 0-9a-z etc., after using this in a form (it worked really
> neat!!), I realized that I needed to allow additional specific
> characters such as {}[]<>
>[/color]

all you have to do is add the extra characters to the pattern, except that
some of them need to be escaped like () and []

$strippedtext = preg_replace('/[^0-9a-z\[\]\(\)<>]/i','',$originaltext);

see
http://www.php.net/manual/en/function.preg-replace.php
http://www.php.net/manual/en/pcre.pattern.syntax.php

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
  #7  
Old July 17th, 2005, 01:31 AM
marius ursache
Guest
 
Posts: n/a
Default Re: Stripping Data Help Needed

Ralph Freshour wrote:
[color=blue]
> I'm taking text from a textarea object and want to strip out
> characters other than A-Za-z0-9 before I send the data to MySQL table
> - is there a function I can use to do this in PHP?
>
> Thanks...[/color]

maybe you need striptags (from php)?

--
marius

Free your mind; the rest will follow.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.