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... 6 4906
On 12-Oct-2003, Ralph Freshour <ra***@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);
--
Tom Thackrey www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
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"
<us***********@nospam.com> wrote: On 12-Oct-2003, Ralph Freshour <ra***@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);
On 12-Oct-2003, Ralph Freshour <ra***@primemail.com> wrote: On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey" <us***********@nospam.com> wrote:
On 12-Oct-2003, Ralph Freshour <ra***@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);
How would I handle special characters like single and double quotes? forward and backward slashes?
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 ja*********@willglen.net (it's reserved for spammers)
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"
<us***********@nospam.com> wrote: On 12-Oct-2003, Ralph Freshour <ra***@primemail.com> wrote:
On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey" <us***********@nospam.com> wrote:
> >On 12-Oct-2003, Ralph Freshour <ra***@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);
How would I handle special characters like single and double quotes? forward and backward slashes?
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().
On 12-Oct-2003, Ralph Freshour <ra***@primemail.com> wrote: On Mon, 13 Oct 2003 02:30:14 GMT, "Tom Thackrey" <us***********@nospam.com> wrote:
On 12-Oct-2003, Ralph Freshour <ra***@primemail.com> wrote:
On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey" <us***********@nospam.com> wrote:
> >On 12-Oct-2003, Ralph Freshour <ra***@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); How would I handle special characters like single and double quotes? forward and backward slashes?
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().
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 {}[]<>
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 ja*********@willglen.net (it's reserved for spammers)
Ralph Freshour 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?
Thanks...
maybe you need striptags (from php)?
--
marius
Free your mind; the rest will follow. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Patrick |
last post by:
Hello, after learning that I was taking a class in VB.NET, I have been
drafted to solve all my companies VB/scripting problems - hey, I should know
everything; I've already taken 6 classes ;) I...
|
by: Colin Steadman |
last post by:
My ASP page allows user to enter comments into a form. To avoid
errors I'm having to strip out double quotes before saving to the
database. Is there anyway to encode these so that I can store...
|
by: Raj |
last post by:
Hi
I was hoping someone could suggest a simple way of stripping non-numeric
data from a string of numbers.
For example, if I have "ADB12458789\n"
I would like to remove the letters and the...
|
by: Lu |
last post by:
Hi, i am currently working on ASP.Net v1.0 and is encountering the following
problem. In javascript, I'm passing in:
"somepage.aspx?QSParameter=<RowID>Chèques</RowID>" as part of the query...
|
by: Spondishy |
last post by:
Hi,
I'm looking for help with a regular expression and c#.
I want to remove all tags from a piece of html except the following.
<a>
<b>
<h1>
<h2>
|
by: Edward Elliott |
last post by:
I'm looking for the "best" way to strip a large set of chars from a filename
string (my definition of best usually means succinct and readable). I
only want to allow alphanumeric chars, dashes,...
|
by: Medros |
last post by:
I understand that you can strip html out of a txt file so that all the
information is left is the visable information that is needed (e.g.
everything that has < > around is gone). My question is...
|
by: FFMG |
last post by:
Hi,
I have a form that allows users to comment, add entries and so on.
But what a lot of them do is copy and paste directly from MS Word to my
forms.
almost all browsers will accept the post...
|
by: Tim Cook |
last post by:
Hi All,
I just ran into an issue with the rstrip method when using it on path
strings.
When executing a function I have a need to strip off a portion of the
current working directory and add...
|
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...
|
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...
|
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,...
|
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...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |