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 4915
On 12-Oct-2003, Ralph Freshour <ra***@primemai l.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','',$original text);
--
Tom Thackrey www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@wil lglen.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***@primemai l.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?
$strippedtex t = preg_replace('/[^0-9a-z]/i','',$original text);
On 12-Oct-2003, Ralph Freshour <ra***@primemai l.com> wrote: On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey" <us***********@ nospam.com> wrote:
On 12-Oct-2003, Ralph Freshour <ra***@primemai l.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? $strippedtex t = preg_replace('/[^0-9a-z]/i','',$original text);
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*********@wil lglen.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***@primemai l.com> wrote:
On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey" <us***********@ nospam.com> wrote:
> >On 12-Oct-2003, Ralph Freshour <ra***@primemai l.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? > >$strippedtex t = preg_replace('/[^0-9a-z]/i','',$original text);
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***@primemai l.com> wrote: On Mon, 13 Oct 2003 02:30:14 GMT, "Tom Thackrey" <us***********@ nospam.com> wrote:
On 12-Oct-2003, Ralph Freshour <ra***@primemai l.com> wrote:
On Mon, 13 Oct 2003 01:25:34 GMT, "Tom Thackrey" <us***********@ nospam.com> wrote:
> >On 12-Oct-2003, Ralph Freshour <ra***@primemai l.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? > >$strippedtex t = preg_replace('/[^0-9a-z]/i','',$original text); 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','',$original text);
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*********@wil lglen.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 should have been quiet about
it, but then I would never be reimbursed. Oh well.
I have been asked to write a program to ping a NetBIOS name, get the IP, and
compare the 3rd octet to a list to get the computer's location. So far, I
can ping the IP,...
|
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 them
instead, in the way was an URLEncode works?
TIA,
Col
|
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 newline from this string.
I am new to C so am sure this is simple ut I don't know how to do it! Sorry!
|
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
string. However, in the code behind when I tried to get the query string
value by calling Request.QueryString("QSParameter"), the value I got is:
"<RowID>Chques</RowID>". The special character "è" has been stripped out.
The web.config file is...
|
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, and periods. This is what I
would write in Perl (bless me father, for I have sinned...):
$filename =~ tr/\w.-//cd, or equivalently
$filename =~ s///
I could just use re.sub like the second example, but that's a bit overkill.
I'm trying to...
|
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 that I have a
table of information that I need to be fed into a program as such. Well
kind of I need the program to read it just as you would on paper and be
able to use that information like it was entered. I am unsure how strip
so much away just...
|
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 and give the impression that
everything is saved properly.
But, that is not the case when it comes time to displaying the message
|
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 on a path to a log file. Initially
this worked great but then I added a branch in SVN which caused the path
to contain 'LNCCWorkshop'. The rstrip() then began removing the
characters 'shop' leaving an incorrect path to the log file. When I
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |