|
Posted by Adam i Agnieszka Gasiorowski FNORD on 11/07/00 11:31
On 2005-10-31 08:41:59 +0000, Ewoud Dronkert
<firstname@lastname.net.invalid> 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!!
[Back to original message]
|