I'm trying to write a function that will trim and strip new line
character returns from submitted $_POST values. Does this look serviceable?
function trim_data($form data)
{
foreach ($formdata as $key => $value)
{
$value = preg_replace("( \r\n|\n|\r|\t)" , "", $value);
$newdata[trim($key)] = trim($value);
}
return $newdata;
} 5 5948
Sure, or just use:
$value = str_replace(arr ay("\r", "\n", "\t"), '', $value);
It's probably a little bit faster than preg_replace().
JackM wrote: $value = preg_replace("( \r\n|\n|\r|\t)" , "", $value);
That is not a pattern, it needs pattern delimiters at the start and end.
You don't need the parentheses because there's nothing outside them. Use a
quantifier to match series of newlines/tabs. Use a character class to
match different combinations of characters. I always use single quotes
around patterns to minimize the use of backslashes.
$value = preg_replace('/[\r\n\t]+/', '', $value);
--
E. Dronkert
JackM wrote: I'm trying to write a function that will trim and strip new line character returns from submitted $_POST values. Does this look serviceable?
function trim_data($form data) { foreach ($formdata as $key => $value) { $value = preg_replace("( \r\n|\n|\r|\t)" , "", $value); $newdata[trim($key)] = trim($value);
} return $newdata; }
ZeldorBlat wrote: $value = str_replace(arr ay("\r", "\n", "\t"), '', $value);
Ewoud Dronkert wrote:
$value = preg_replace('/[\r\n\t]+/', '', $value);
Interesting. So what would the preferred method be or is that just
splitting hairs?
JackM wrote: ZeldorBlat wrote:
>> $value = str_replace(arr ay("\r", "\n", "\t"), '', $value);
Ewoud Dronkert wrote:
> $value = preg_replace('/[\r\n\t]+/', '', $value);
Interesting. So what would the preferred method be or is that just splitting hairs?
In principle, I say prefer str_replace. Maybe if $value contained lots of
consecutive \r, \n or \t, the regexp might even be a little faster?
Actually I didn't think about the possibility to use an array argument for
str_replace so just used a regexp, with which I'm quite comfortable.
--
E. Dronkert
On 2005-10-31 08:41:59 +0000, Ewoud Dronkert
<fi*******@last name.net.invali d> said: JackM wrote: $value = preg_replace("( \r\n|\n|\r|\t)" , "", $value);
That is not a pattern, it needs pattern delimiters at the start and end. You don't need the parentheses because there's nothing outside them. Use a quantifier to match series of newlines/tabs. Use a character class to match different combinations of characters. I always use single quotes around patterns to minimize the use of backslashes.
$value = preg_replace('/[\r\n\t]+/', '', $value);
You are right about the delimiters, but
wrong about the pattern. I did not test
it, but using a greedy quantifier instead
of alternative is not a good idea. I would
write it as a non capturing (?:) and put
the most probable alternative first, which
is, correctly, \r\n (Windows), the rest of
them don't matter that much as in almost 9/10
PCRE engine will end matching at the first
branch (it short-circuits) ---- Windows clients
are 90%+ of all accessing web pages. Feel free to
correct me if I'm wrong.
--*
I am the One. I am A vampire A-calling for your love! A.A!
I am the fire that burns within your blood. I am the One!!
No bars or chains can keep me from your bed! I am the One!
Nothing on earth can get me from your head! I am the One!! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Radioactive Man |
last post by:
anyone know of a function like "raw_input", which collects a string
from the user entry, but one where I can set a time limit, as follows:
time_limit = 10 # seconds
user_answer = function_xyz("GIVE ME AN ANSWER: ", time_limit)
The problem with "raw_input" is that it will stop unattended script
indefinitely. I'm looking for a function that does the exact same
thing, but with a time limit feature, and preferably one that returns
|
by: alex.mcshane |
last post by:
Hi - I would be grateful for any advice on the following.
Within DB2 for OS/390, the STRIP Scaler Function is available.
Its function is, for example, to remove leading zeros from a string.
For example: -
Strip(Char(Digits(v_cntrct_no_seed)),L,'0')
- v_cntrct_no_seed is defined as Integer
- Char and Digits return a character representation of a number with
|
by: kennethfine |
last post by:
I'm transitioning from ASP development, please excuse
these basic questions. One thing I did often in ASP was
create a "translate" function to render one string to
another, strip out excess carriage returns, etc.
I want to do the same thing in ASP.NET. I have a mail
component that will accept HTML, but it requires all HTML
to be listed on a single line. It takes the syntax:
msgObj.BodyParts.Add(" <html markup here> "),
|
by: VB Programmer |
last post by:
I am trying to create a function which strips out ALL occurances of a
particular phrase in a string. It returns the cleaned up string. I gave it
an argument of "1###2###3###4". When it finally gets to the Return
statement it DOES return the correct thing, but by the time it finally
"unravels" it returns nothing. Any ideas????
Private Function StripOutPounds(ByVal strMsg As String) As String
Try
Dim s As String
|
by: teddysnips |
last post by:
I have to write an application to do some data cleansing. It's a
Contact database, but over a number of years there are multiple
companies which are all essentially the same entity. For each company
there are also multiple contacts, some of which may be congruent.
It's a very simple app. with only two forms. The first form shows two
lists. The left-hand list is a Single-Select showing all the companies.
The user chooses one company -...
| |
by: michael.bierenfeld |
last post by:
Hello,
we are currently porting some sql programs from vm/vse to aix. On The
VSE Machine (DB2) the following is valid :
-lots of crap - but in the where clause of the statement :
WHERE
JOBDESC = (STRIP(:HV-JOB) CONCAT '/in')
|
by: idoerg |
last post by:
Hi all,
I am running Python 2.5 on Feisty Ubuntu. I came across some code that
is substantially slower when in a method than in a function.
################# START SOURCE #############
# The function
def readgenome(filehandle):
s = ''
|
by: Serman D. |
last post by:
Background: The Payment Card Industry (PCI) Data Security Standard
(PCI DSS) is a standard for financial institutions. It requires
sensitive information, such as credit card numbers, to be "unreadable
anywhere it is stored" using hashing, truncation or encryption.
I am looking for a simple truncation function that replaces the last
four digits in the given numeric with four characters (e.g. '*'). As
as Perl programmer (where a simple...
|
by: Fredrik Lundh |
last post by:
Beema Shafreen wrote:
note that you put the "return" statement inside the loop, so returning
only one line is the expected behaviour.
result = "%s\t%s\t%s" %(id,gene_symbol,ptms)
data_lis.append(result)
and then return the list when done:
|
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: 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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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...
| |