Re: [PHP] preg_match problem

2007-01-25 Thread Jim Lucas

Beauford wrote:

Here is my rendition of what I think you are looking for.

$str = 'tab()/space( )/[EMAIL PROTECTED]*();:...';

if ( preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|', $str) ) {
echo 'success';
} else {
echo 'failure';
}



Here is the problem, and it is strange. If I enter each of the above
characters into my form one at a time and hit submit after each one, NO
error is produced for any of them.

If I cut and past this all at once:  [EMAIL PROTECTED]*();:_.\ then an error
IS returned.
If I continue to remove one character at a time, submitting the form each
time, errors ARE still produced.

This is the code in a nutshell:

If(isset($submit)) {

$name = stripslashes($_POST['name']);   I have tried this with and
without

$formerror = array(); unset($result);   I have tried this with and
without

if($result = ValidateString($name)) { $formerror['name'] =
$invalidcharacters;

Function ValidateString($string) {
if (!preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|',
$string) ) {
return invalidchars;
}
}
}

Form Stuff
input name=name size=30 type=text
/form



Thanks


Here is a link to a page that has this on it, but with the added '

Plus a link to the source code for it.

Jim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-25 Thread Beauford
Hi Jim, 

Thanks for all the help, but where is the link.  

 Here is a link to a page that has this on it, but with the added '
 
 Plus a link to the source code for it.
 
 Jim
 
 --
 PHP General Mailing List (http://www.php.net/) To 
 unsubscribe, visit: http://www.php.net/unsub.php
 
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-25 Thread Jim Lucas

Beauford wrote:
Hi Jim, 

Thanks for all the help, but where is the link.  


Here is a link to a page that has this on it, but with the added '

Plus a link to the source code for it.

Jim

--
PHP General Mailing List (http://www.php.net/) To 
unsubscribe, visit: http://www.php.net/unsub.php







sorry

that is what I get for sending things that early in the morning.  :(

http://www.cmsws.com/examples/php/preg_match/example01.php


--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different 
strings. But there are times for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-25 Thread Richard Lynch
On Thu, January 25, 2007 9:53 am, Jim Lucas wrote:
 http://www.cmsws.com/examples/php/preg_match/example01.php

The \t inside of '' has no special meaning.
So you don't have a TAB character in there.

You need  to get \t to mean TAB

Once you do that, you should then escape the $ with \$ instead of just
$ in order to be blatantly clear, even though $% is not going to parse
as a variable anyway.

Also, you really ought to use http://php.net/htmlentities on any data
going to the browser, as what we see and what you expect won't match
up otherwise.
echo String is: ', htmlentities($str), 'br /\n;

Finally, to be completely pedantic, echoing out raw $_GET data is a
big XSS hole waiting to be exploited.  Start reading here:
http://phpsec.org/

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-24 Thread Beauford
 Here is my rendition of what I think you are looking for.
 
 $str = 'tab(  )/space( )/[EMAIL PROTECTED]*();:...';
 
 if ( preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|', $str) ) {
   echo 'success';
 } else {
   echo 'failure';
 }
 

Here is the problem, and it is strange. If I enter each of the above
characters into my form one at a time and hit submit after each one, NO
error is produced for any of them.

If I cut and past this all at once:  [EMAIL PROTECTED]*();:_.\ then an error
IS returned.
If I continue to remove one character at a time, submitting the form each
time, errors ARE still produced.

This is the code in a nutshell:

If(isset($submit)) {

$name = stripslashes($_POST['name']);   I have tried this with and
without

$formerror = array(); unset($result);   I have tried this with and
without

if($result = ValidateString($name)) { $formerror['name'] =
$invalidcharacters;

Function ValidateString($string) {
if (!preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|',
$string) ) {
return invalidchars;
}
}
}

Form Stuff
input name=name size=30 type=text
/form



Thanks

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-24 Thread Paul Novitski

At 1/24/2007 01:13 PM, Beauford wrote:

 Here is my rendition of what I think you are looking for.

 $str = 'tab(  )/space( )/[EMAIL PROTECTED]*();:...';

 if ( preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|', $str) ) {
   echo 'success';
 } else {
   echo 'failure';
 }


Here is the problem, and it is strange. If I enter each of the above
characters into my form one at a time and hit submit after each one, NO
error is produced for any of them.

If I cut and past this all at once:  [EMAIL PROTECTED]*();:_.\ then an error
IS returned.


Are you really including a backslash as your final character?  Are 
you escaping it?  Is the error you're getting the result of the 
sequence \ or \' which eats up your ending delimiter?


Beauford, all of this stuff you're trying to do is elementary regular 
expression work.  The problems you're having are undoubtedly very 
easy to solve, but so far helping you has been guesswork because we 
haven't actually seen the scripts you're actually running.  To help 
us help you get past this log jam, give us all the material we need 
to analyze your problem.


1) Specify exactly which error messages you're getting.
2) Give us an URL to a test page that displays the strings and 
patterns and the error messages that result.
3) Copy the PHP script in step 2) with a .txt file extension and post 
that as well so we can proofread your code.


My own personal experience is that if you document and demonstrate 
your problem well enough that someone else can actually help you, the 
chances are that doing so will reveal the solution to you, like magic.


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-23 Thread Martin Alterisio

2007/1/22, Beauford [EMAIL PROTECTED]:



... much blah blah blah ...

I've probably read 100 pages on this, and no matter what I try it doesn't
work. Including all of what you suggested above - is my PHP possessed?

if(preg_match(/[EMAIL PROTECTED]()*;:_.'/\\ ]+$/, $string)) { gives me
this error.

Warning: preg_match() [function.preg-match]: Unknown modifier '\' in
/constants.php on line 107

So if If you wouldn't mind, could you show me exactly what I need right
from
the beginning and explain why it works.

i.e.

if(preg_match(what goes here, $string)) {
Echo You got it;



if (preg_match('/[EMAIL PROTECTED]()*;:_.'\\/ ]+$/', $string))

Use single quotes and double back-slashes. PHP strings also have escape
sequences that use the back-slash as escape character, that's why you have
to double them. And single quotes to avoid the $ character interpreted as
the start of a variable.

PS: Will we be risking going the perl way if we ask that PHP supported
regular expressions natively (I mean: without having to provide them as
strings)?


Re: [PHP] preg_match problem

2007-01-23 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-23 09:52:17 -0300:
 2007/1/22, Beauford [EMAIL PROTECTED]:
 PS: Will we be risking going the perl way if we ask that PHP supported
 regular expressions natively (I mean: without having to provide them as
 strings)?

Yes.  I don't know about other people's objections (I have no problem
with the look and feel of naked regular expressions, but the parser
would get a bit hairier.  I mean, parsers.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-23 Thread Paul Novitski

At 1/23/2007 04:52 AM, Martin Alterisio wrote:

if (preg_match('/[EMAIL PROTECTED]()*;:_.'\\/ ]+$/', $string))



Close but no cigar.  Because you're using apostrophe to quote the 
expression, PHP interprets the apostrophe inside the character class 
as ending the quoted expressions and fails.  Both PHP and PREG need 
you to escape any character inside a string that's used to delimit 
the string itself.


(I think it's just as important to test the code we offer to solve 
problems on the list as it is to research problems before posting 
them.  This is all getting archived)


Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com  


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-23 Thread Beauford
 
 if (preg_match('/[EMAIL PROTECTED]()*;:_.'\\/ ]+$/', $string))
 
 Use single quotes and double back-slashes. PHP strings also 
 have escape sequences that use the back-slash as escape 
 character, that's why you have to double them. And single 
 quotes to avoid the $ character interpreted as the start of a 
 variable.
 
 PS: Will we be risking going the perl way if we ask that PHP 
 supported regular expressions natively (I mean: without 
 having to provide them as strings)?

I have tried all the examples posted in the last couple of days, and none of
them, including the above work. Is there another solution to this, as this
just seems to be way to buggy?

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
/constants.php on line 107

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
//constants.php on line 107

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
/constants.php on line 107

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
/constants.php on line 107

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
//constants.php on line 107

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in
//constants.php on line 107

Parse error: syntax error, unexpected ']' in //constants.php on line 107 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-23 Thread Beauford
 
 You need to escape that forward slash in the character class:
 
  preg_match(/[EMAIL PROTECTED]()*;:_.'\/
 
 Also, you've got only two backslashes in your char class.  PHP is 
 reducing this to a single backslash before the space character.  I 
 think you intend this to be two backslashes in the pattern so you 
 need four backslashes in PHP:
 
  preg_match(/[EMAIL PROTECTED]()*;:_.'\/ ]+$/, $string)
 
On top of this, every time a ' is entered it gets preceded by \. If I just
check for the characters like below that doesn't happen. Totally confused.

if(preg_match(/^[-A-Za-z0-9_.' ]+$/, $string)) {

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-23 Thread Jim Lucas


if (preg_match('/[EMAIL PROTECTED]()*;:_.'\\/ ]+$/', $string))



Here is my rendition of what I think you are looking for.

$str = 'tab()/space( )/[EMAIL PROTECTED]*();:...';

if ( preg_match('|[EMAIL PROTECTED]*();:_. /\t-]+$|', $str) ) {
echo 'success';
} else {
echo 'failure';
}



--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different 
strings. But there are times for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-23 Thread Jim Lucas

Beauford wrote:
 

You need to escape that forward slash in the character class:

 preg_match(/[EMAIL PROTECTED]()*;:_.'\/

Also, you've got only two backslashes in your char class.  PHP is 
reducing this to a single backslash before the space character.  I 
think you intend this to be two backslashes in the pattern so you 
need four backslashes in PHP:


 preg_match(/[EMAIL PROTECTED]()*;:_.'\/ ]+$/, $string)


On top of this, every time a ' is entered it gets preceded by \. If I just
check for the characters like below that doesn't happen. Totally confused.

if(preg_match(/^[-A-Za-z0-9_.' ]+$/, $string)) {


check out magic_quote_gpc??

use the funciton get_magic_quotes_gpc() to determine if it is on and 
run stripslashes() on the value if you find that it is on.


--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different 
strings. But there are times for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-23 Thread Paul Novitski

At 1/23/2007 09:50 AM, Beauford wrote:

  preg_match(/[EMAIL PROTECTED]()*;:_.'\/ ]+$/, $string)

On top of this, every time a ' is entered it gets preceded by \. If I just
check for the characters like below that doesn't happen. Totally confused.

if(preg_match(/^[-A-Za-z0-9_.' ]+$/, $string)) {



You don't need to escape the apostrophe if the pattern isn't quoted 
with apostrophes in PHP or delimited by apostrophes in the PREG 
pattern.  But generally there's no harm in escaping characters 
unnecessarily; it just makes for messier code.


Here is a simple test of the regexp I recommended yesterday using the pattern:
/[EMAIL PROTECTED]()*;:_.'\/ ]+$/
http://juniperwebcraft.com/test/regexp_test_2007-01-23.php

If you're still having trouble getting this to work, please post a 
link to a page that demonstrates it not working and give us the 
complete PHP statements so we can find your error.


As an additional resource, here's Oliver Steele's RegExp workbench:
http://osteele.com/tools/rework/

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-23 Thread Beauford
 You don't need to escape the apostrophe if the pattern isn't 
 quoted with apostrophes in PHP or delimited by apostrophes in 
 the PREG pattern.  But generally there's no harm in escaping 
 characters unnecessarily; it just makes for messier code.
 
 Here is a simple test of the regexp I recommended yesterday 
 using the pattern:
  /[EMAIL PROTECTED]()*;:_.'\/ ]+$/

Ok, after a lot of testing and seriously losing it, this is what appears to
be the issue. Blank lines or \n or some kind of carriage return is  not
allowed. The first example works, the others don't. I tried adding a
carriage return, but who knows, I may be way out on left field with this.
It's insane.

sdfasd:spacespacespace
http://fsdgas.asfs.asfs/   dfgfasg

---

sdfasd:spacespacespace

http://fsdgas.asfs.asfs/   dfgfasg


---

Abcdefg

[EMAIL PROTECTED]

If there is another solution to doing this, I would definitely prefer it.
This is just way to buggy, and I ran out of patience a week ago. This is on
a production site, and is the only reason I have tried to get it working.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match problem

2007-01-22 Thread Beauford
I'm trying to get this but not quite there. I want to allow the following
characters.

[EMAIL PROTECTED]()*;:_.'/\ and a space.

Is there a special order these need to be in or escaped somehow. For
example, if I just allow _' the ' is fine, if I add the other characters,
the ' gets preceded by a \ and an error is returned. If I take the ' out of
the sting below it works fine, I get no errors returned. I am also using
stripslashes on the variable.

This is my code. (although I have tried various things with it trying to get
it right)

if(preg_match(/[EMAIL PROTECTED]\(\)\*;:_.\'\$ ]+$/, $string)) {

Thanks

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-22 Thread Paul Novitski

At 1/22/2007 03:04 PM, Beauford wrote:

I'm trying to get this but not quite there. I want to allow the following
characters.

[EMAIL PROTECTED]()*;:_.'/\ and a space.

Is there a special order these need to be in or escaped somehow. For
example, if I just allow _' the ' is fine, if I add the other characters,
the ' gets preceded by a \ and an error is returned. If I take the ' out of
the sting below it works fine, I get no errors returned. I am also using
stripslashes on the variable.

This is my code. (although I have tried various things with it trying to get
it right)

if(preg_match(/[EMAIL PROTECTED]\(\)\*;:_.\'\$ ]+$/, $string)) {



Please read this page:

Pattern Syntax -- Describes PCRE regex syntax
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php

specifically the section on character classes:
http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php#regexp.reference.squarebrackets

In PREG there are few characters that you need to escape in a 
character class expression:


1) ^ must be escaped (\^) if it's the first character (it negates the 
match when it's unescaped in the first position).


2) ] must be escaped (\]) unless it's the first character of the 
class (it closes the class if it appears later and is not escaped).


3) \ must be escaped (\\) if you're referring to the backslash 
character rather than using backslash to escape another character.


4) Control codes such as \b for backspace (not to be confused with \b 
which means word boundary outside of a character class).



In addition, you may need to escape certain characters in PHP if 
you're expressing the RegExp pattern in a quoted string, such as 
single or double quotes (whichever you're using to quote the pattern):


'[\']'  escape the apostophe
['\]  escape the quotation mark

Those are PHP escapes -- by the time PREG sees the pattern, the PHP 
compiler has rendered it to:


[']

And then of course there's the complication that both PREG and PHP 
use the backslash as the escape character, so the pattern:


[\\]  escape the backslash

must be expressed in PHP as:

[]  escape the escape and the backslash

Interestingly, PHP compiles both \\\ and  as \\, go figure.  I 
use  to escape both backslashes to maintain some semblance of 
logic and order in these eye-crossing expressions.


Because PHP requires quotes to be escaped, I find it easier to write 
 debug patterns in PHP if I express them in heredoc where quoting 
and most escaping is unnecessary:


$sPattern = _
[']
_;

becomes the PREG pattern ['\\].


So to address your character class:


[EMAIL PROTECTED]()*;:_.'/\ and a space.


I'd use the pattern:

[EMAIL PROTECTED]()*;:_.'/\\ ]

where the only character I need to escape is the backslash itself.

In PHP this would be:

$sPattern = '[EMAIL PROTECTED]()*;:_.\'/ ]';
(escaped apostrophe  blackslash)
or:
$sPattern = [EMAIL PROTECTED]()*;:_.'/ ];
(escaped blackslash)
or:
$sPattern = _
[EMAIL PROTECTED]()*;:_.'/ ]
_;
(escaped blackslash)

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-22 Thread Beauford
 

 -Original Message-
 From: Paul Novitski [mailto:[EMAIL PROTECTED] 
 Sent: January 22, 2007 6:58 PM
 To: PHP
 Subject: Re: [PHP] preg_match problem
 
 At 1/22/2007 03:04 PM, Beauford wrote:
 I'm trying to get this but not quite there. I want to allow the 
 following characters.
 
 [EMAIL PROTECTED]()*;:_.'/\ and a space.
 
 Is there a special order these need to be in or escaped somehow. For 
 example, if I just allow _' the ' is fine, if I add the other 
 characters, the ' gets preceded by a \ and an error is 
 returned. If I 
 take the ' out of the sting below it works fine, I get no errors 
 returned. I am also using stripslashes on the variable.
 
 This is my code. (although I have tried various things with 
 it trying 
 to get it right)
 
 if(preg_match(/[EMAIL PROTECTED]\(\)\*;:_.\'\$ ]+$/, $string)) {
 
 
 Please read this page:
 
 Pattern Syntax -- Describes PCRE regex syntax 
 http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php
 
 specifically the section on character classes:
 http://ca.php.net/manual/en/reference.pcre.pattern.syntax.php#
 regexp.reference.squarebrackets
 
 In PREG there are few characters that you need to escape in a 
 character class expression:
 
 1) ^ must be escaped (\^) if it's the first character (it 
 negates the match when it's unescaped in the first position).
 
 2) ] must be escaped (\]) unless it's the first character of 
 the class (it closes the class if it appears later and is not 
 escaped).
 
 3) \ must be escaped (\\) if you're referring to the 
 backslash character rather than using backslash to escape 
 another character.
 
 4) Control codes such as \b for backspace (not to be confused 
 with \b which means word boundary outside of a character class).
 
 
 In addition, you may need to escape certain characters in PHP if 
 you're expressing the RegExp pattern in a quoted string, such as 
 single or double quotes (whichever you're using to quote the pattern):
 
  '[\']'  escape the apostophe
  ['\]  escape the quotation mark
 
 Those are PHP escapes -- by the time PREG sees the pattern, the PHP 
 compiler has rendered it to:
 
  [']
 
 And then of course there's the complication that both PREG and PHP 
 use the backslash as the escape character, so the pattern:
 
  [\\]  escape the backslash
 
 must be expressed in PHP as:
 
  []  escape the escape and the backslash
 
 Interestingly, PHP compiles both \\\ and  as \\, go figure.  I 
 use  to escape both backslashes to maintain some semblance of 
 logic and order in these eye-crossing expressions.
 
 Because PHP requires quotes to be escaped, I find it easier to write 
  debug patterns in PHP if I express them in heredoc where quoting 
 and most escaping is unnecessary:
 
 $sPattern = _
 [']
 _;
 
 becomes the PREG pattern ['\\].
 
 
 So to address your character class:
 
 [EMAIL PROTECTED]()*;:_.'/\ and a space.
 
 I'd use the pattern:
 
  [EMAIL PROTECTED]()*;:_.'/\\ ]
 
 where the only character I need to escape is the backslash itself.
 
 In PHP this would be:
 
  $sPattern = '[EMAIL PROTECTED]()*;:_.\'/ ]';
  (escaped apostrophe  blackslash)
 or:
  $sPattern = [EMAIL PROTECTED]()*;:_.'/ ];
  (escaped blackslash)
 or:
  $sPattern = _
 [EMAIL PROTECTED]()*;:_.'/ ]
 _;
  (escaped blackslash)

I've probably read 100 pages on this, and no matter what I try it doesn't
work. Including all of what you suggested above - is my PHP possessed? 

if(preg_match(/[EMAIL PROTECTED]()*;:_.'/\\ ]+$/, $string)) { gives me
this error.

Warning: preg_match() [function.preg-match]: Unknown modifier '\' in
/constants.php on line 107

So if If you wouldn't mind, could you show me exactly what I need right from
the beginning and explain why it works.

i.e. 

if(preg_match(what goes here, $string)) {
Echo You got it;  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-22 Thread Paul Novitski

At 1/22/2007 04:56 PM, Beauford wrote:

I've probably read 100 pages on this, and no matter what I try it doesn't
work. Including all of what you suggested above - is my PHP possessed?

if(preg_match(/[EMAIL PROTECTED]()*;:_.'/\\ ]+$/, $string)) { gives me
this error.

Warning: preg_match() [function.preg-match]: Unknown modifier '\' in
/constants.php on line 107

So if If you wouldn't mind, could you show me exactly what I need right from
the beginning and explain why it works.

i.e.

if(preg_match(what goes here, $string)) {
Echo You got it;



Beauford,

Because you're using forward slashes /.../ to delimit your pattern, 
regexp is using the / in your character class to terminate your pattern:


/[EMAIL PROTECTED]()*;:_.'/

Then it's looking at the subsequent characters as pattern modifiers 
and gacking on the backslash.  Even if you had a character there that 
it could accept as a pattern modifier, the character class would be 
incomplete (no closing bracket) so the pattern is doomed to fail.


You need to escape that forward slash in the character class:

preg_match(/[EMAIL PROTECTED]()*;:_.'\/

Also, you've got only two backslashes in your char class.  PHP is 
reducing this to a single backslash before the space character.  I 
think you intend this to be two backslashes in the pattern so you 
need four backslashes in PHP:


preg_match(/[EMAIL PROTECTED]()*;:_.'\/ ]+$/, $string)

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-21 Thread Martin Alterisio

2007/1/20, Arpad Ray [EMAIL PROTECTED]:


Martin Alterisio wrote:
 Double slash to prevent PHP interpreting the slashes. Also using single
 quotes would be a good idea:

 if (preg_match('/[\\w\\x2F]{6,}/',$a))


Just switching to single quotes would do the trick - you don't need to
escape anything but single quotes, and backslashes if they are the last
character.

Arpad



It's true, it works but I still believe is best to do both, since you may
forget to doubleslash when it's imperative for the expression to work, even
when using single quotes.


Re: [PHP] preg_match problem

2007-01-20 Thread Martin Alterisio

Double slash to prevent PHP interpreting the slashes. Also using single
quotes would be a good idea:

if (preg_match('/[\\w\\x2F]{6,}/',$a))


2007/1/19, Németh Zoltán [EMAIL PROTECTED]:


Hi all,

I have a simple checking like

if (preg_match(/[\w\x2F]{6,}/,$a))

as I would like to allow all word characters as mentioned at
http://hu2.php.net/manual/hu/reference.pcre.pattern.syntax.php
plus the '/' character, and at least 6 characters.

But it throws

Warning: preg_match(): Unknown modifier ']'

and returns false for abc/de/ggg which string should be okay.
If I omit the \x2F, everything works fine but / characters are not
allowed. Anyone knows what I'm doing wrong? Maybe / characters can not
be put in patterns like this?

Thanks in advance,
Zoltán Németh

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] preg_match problem

2007-01-20 Thread Arpad Ray

Martin Alterisio wrote:

Double slash to prevent PHP interpreting the slashes. Also using single
quotes would be a good idea:

if (preg_match('/[\\w\\x2F]{6,}/',$a))



Just switching to single quotes would do the trick - you don't need to 
escape anything but single quotes, and backslashes if they are the last 
character.


Arpad

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match problem

2007-01-19 Thread Németh Zoltán
Hi all,

I have a simple checking like

if (preg_match(/[\w\x2F]{6,}/,$a))

as I would like to allow all word characters as mentioned at
http://hu2.php.net/manual/hu/reference.pcre.pattern.syntax.php
plus the '/' character, and at least 6 characters.

But it throws

Warning: preg_match(): Unknown modifier ']'

and returns false for abc/de/ggg which string should be okay.
If I omit the \x2F, everything works fine but / characters are not
allowed. Anyone knows what I'm doing wrong? Maybe / characters can not
be put in patterns like this?

Thanks in advance,
Zoltán Németh

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-19 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-19 15:25:38 +0100:
 Hi all,
 
 I have a simple checking like
 
 if (preg_match(/[\w\x2F]{6,}/,$a))
 
 as I would like to allow all word characters as mentioned at
 http://hu2.php.net/manual/hu/reference.pcre.pattern.syntax.php
 plus the '/' character, and at least 6 characters.
 
 But it throws
 
 Warning: preg_match(): Unknown modifier ']'
 
 and returns false for abc/de/ggg which string should be okay.
 If I omit the \x2F, everything works fine but / characters are not
 allowed. Anyone knows what I'm doing wrong? Maybe / characters can not
 be put in patterns like this?

1. You're making your life harder with those double quotes.  \x2F is
   interpolated by PHP, before the PCRE library has a chance to see the
   string.
2. Use a different delimiter and you'll be able to use slash characters
   in the pattern freely.

   preg_match('~[\w/]{6,}~', $a);

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2007-01-19 Thread Németh Zoltán
On p, 2007-01-19 at 15:39 +, Roman Neuhauser wrote:
 # [EMAIL PROTECTED] / 2007-01-19 15:25:38 +0100:
  Hi all,
  
  I have a simple checking like
  
  if (preg_match(/[\w\x2F]{6,}/,$a))
  
  as I would like to allow all word characters as mentioned at
  http://hu2.php.net/manual/hu/reference.pcre.pattern.syntax.php
  plus the '/' character, and at least 6 characters.
  
  But it throws
  
  Warning: preg_match(): Unknown modifier ']'
  
  and returns false for abc/de/ggg which string should be okay.
  If I omit the \x2F, everything works fine but / characters are not
  allowed. Anyone knows what I'm doing wrong? Maybe / characters can not
  be put in patterns like this?
 
 1. You're making your life harder with those double quotes.  \x2F is
interpolated by PHP, before the PCRE library has a chance to see the
string.
 2. Use a different delimiter and you'll be able to use slash characters
in the pattern freely.
 
preg_match('~[\w/]{6,}~', $a);
 

Thank you very much, it's working fine now.

Zoltán Németh

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem

2007-01-19 Thread Tim
Not a big regex expert, but first off i would recommend not using / as a
delimiter for your pattern if you are trying to catch forward slashes in
your text.

I would use a pattern like:

#[a-zA-Z0-9/]{6,}#


Regards,

Tim

 -Message d'origine-
 De : Németh Zoltán [mailto:[EMAIL PROTECTED]
 Envoyé : vendredi 19 janvier 2007 15:26
 À : php-general@lists.php.net
 Objet : [PHP] preg_match problem
 
 Hi all,
 
 I have a simple checking like
 
 if (preg_match(/[\w\x2F]{6,}/,$a))
 
 as I would like to allow all word characters as mentioned at
 http://hu2.php.net/manual/hu/reference.pcre.pattern.syntax.php
 plus the '/' character, and at least 6 characters.
 
 But it throws
 
 Warning: preg_match(): Unknown modifier ']'
 
 and returns false for abc/de/ggg which string should be okay.
 If I omit the \x2F, everything works fine but / characters are not
 allowed. Anyone knows what I'm doing wrong? Maybe / characters can not
 be put in patterns like this?
 
 Thanks in advance,
 Zoltán Németh
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2006-08-22 Thread Richard Lynch




On Mon, August 21, 2006 2:13 pm, Dave Goodchild wrote:
 On 21/08/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 hi.

 I have to check if the script file belongs to any ov form1.php to
 form6.php files. Need something like:
 preg_match('/form*.php/', $_SERVER['PHP_SELF'])
 wher * kan be any number between 1 and 6.

 Thanks for any help.

 the pattern is form[1-6]+\.php.

Matches form10.php form11.php form12.php ... form16.php form21.php ...

Leave out the + sign, which means 1 or more

And I have a religious conviction that you oughta use \\. inside of '
or  though others find it cluttered.

YMMV

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match problem

2006-08-21 Thread afan
hi.

I have to check if the script file belongs to any ov form1.php to
form6.php files. Need something like:
preg_match('/form*.php/', $_SERVER['PHP_SELF'])
wher * kan be any number between 1 and 6.

Thanks for any help.

-afan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2006-08-21 Thread Dave Goodchild

On 21/08/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


hi.

I have to check if the script file belongs to any ov form1.php to
form6.php files. Need something like:
preg_match('/form*.php/', $_SERVER['PHP_SELF'])
wher * kan be any number between 1 and 6.

Thanks for any help.

the pattern is form[1-6]+\.php.









--
http://www.web-buddha.co.uk
http://www.projectkarma.co.uk


Re: [PHP] preg_match problem

2006-08-21 Thread Alex Turner
I think this pattern would also match form16.php etc, which I think is 
not what afan wanted.


Dave Goodchild wrote:

On 21/08/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


hi.

I have to check if the script file belongs to any ov form1.php to
form6.php files. Need something like:
preg_match('/form*.php/', $_SERVER['PHP_SELF'])
wher * kan be any number between 1 and 6.

Thanks for any help.

the pattern is form[1-6]+\.php.











--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2006-08-21 Thread afan
Works perfect. Thanks!
;)

-afan



 function doMatch($f) {
   echo $f,
   = ,
  (preg_match(#^form[1-6]\.php\$#,basename($f))?true:false),
  \n;
 }

 doMatch(form1.php); // true
 doMatch(form2.php); // true
 doMatch(form3.php); // true
 doMatch(form4.php); // true
 doMatch(form5.php); // true
 doMatch(form6.php); // true
 doMatch(/some/dir/form6.php);   // true
 doMatch(form06.php);// false
 doMatch(/some/dir/form06.php);// false
 doMatch(form16.php);// false
 doMatch(/some/dir/form16.php);// false


 [EMAIL PROTECTED] wrote:
 hi.

 I have to check if the script file belongs to any ov form1.php to
 form6.php files. Need something like:
 preg_match('/form*.php/', $_SERVER['PHP_SELF'])
 wher * kan be any number between 1 and 6.

 Thanks for any help.

 -afan




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_match problem

2006-08-21 Thread Jochem Maas
function doMatch($f) {
echo $f,
  = ,
 (preg_match(#^form[1-6]\.php\$#,basename($f))?true:false),
 \n;
}

doMatch(form1.php);   // true
doMatch(form2.php);   // true
doMatch(form3.php);   // true
doMatch(form4.php);   // true
doMatch(form5.php);   // true
doMatch(form6.php);   // true
doMatch(/some/dir/form6.php); // true
doMatch(form06.php);  // false
doMatch(/some/dir/form06.php);// false
doMatch(form16.php);  // false
doMatch(/some/dir/form16.php);// false


[EMAIL PROTECTED] wrote:
 hi.
 
 I have to check if the script file belongs to any ov form1.php to
 form6.php files. Need something like:
 preg_match('/form*.php/', $_SERVER['PHP_SELF'])
 wher * kan be any number between 1 and 6.
 
 Thanks for any help.
 
 -afan
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match problem/question

2003-04-04 Thread Jason Borgmann
I am getting an error on the following line:

if(preg_match('s/l$//', $string))

The error is:

Warning:  Delimiter must not be alphanumeric or backslash in
/u1/jab/devel/whitespace/whitespace.php on line 136.

I know that pcre in PHP is not exactly interchangeable.  Any ideas on how
to get this to work?  TIA.

-jb
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] preg_match problem/question

2003-04-04 Thread John W. Holmes
 I am getting an error on the following line:
 
 if(preg_match('s/l$//', $string))
 
 The error is:
 
 Warning:  Delimiter must not be alphanumeric or backslash in
 /u1/jab/devel/whitespace/whitespace.php on line 136.
 
 I know that pcre in PHP is not exactly interchangeable.  Any ideas on
how
 to get this to work?  TIA.

Come on man... this is the first paragraph of the chapter on the
Perl-Compatible regular expressions:

The syntax for patterns used in these functions closely resembles Perl.
The expression should be enclosed in the delimiters, a forward slash
(/), for example. Any character can be used for delimiter as long as
it's not alphanumeric or backslash (\). If the delimiter character has
to be used in the expression itself, it needs to be escaped by
backslash. Since PHP 4.0.4, you can also use Perl-style (), {}, [], and
 matching delimiters.

Is it really that hard to figure out? There are examples on the page,
too.

http://www.php.net/manual/en/ref.pcre.php

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_match problem

2002-09-29 Thread Chris N

Ok heres the situation, I have a string like this

$this-_item[title]  = 28.09.02 - Some silly Text (First) (Second);

Im trying to do a preg_match on it to check it to make sure its in a certian
format. Heres my preg_match

preg_match(/^(\d+)\.(\d+)\.(\d+)\s+\-\s+(.+)\s+\((.+)\)$,
$this-_item[title], $matches);
list($all, $one, $two, $three, $four, $five) = $matches;

What Im getting returned in this

$one = 28
$two = 09
$three = 02
$four = Some silly Text
$five = First) (Second

What I want is

$four = Some silly Text (First)
$five = Second

Can anyone see where Im going wrong? The match may be really crude, Im still
pretty new to regular expressions. But it works just fine as long as there
is only one set of ().

Chris N.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php