Re: [PHP] preg_match fails to resolve variable as a subject

2010-12-03 Thread Da Rock

On 12/03/10 16:33, Tamara Temple wrote:


On Dec 2, 2010, at 11:33 PM, Da Rock wrote:


On 11/29/10 09:10, Richard Quadling wrote:
On 27 November 2010 04:45, Da 
Rockphp-l...@herveybayaustralia.com.au  wrote:



On 11/27/10 13:51, Tamara Temple wrote:


On Nov 26, 2010, at 7:28 PM, Da Rock wrote:



On 11/27/10 00:57, Richard Quadling wrote:

On 26 November 2010 00:07, Da 
Rockphp-l...@herveybayaustralia.com.au

 wrote:


preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . 
$command),$matches)




Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.




Haven't tried yet, but isn't that what $ is for? End of line?




$ matches end of line, but since your last match expression is to 
match
explicitly the character '.' before end of line, and there's a 
newline, it
won't match. Again, use trim() to get rid of the newline character 
at the

end of the string returned by exec(). Looking at the output or


And exec only gives one line- the last line of the output of the 
command.

You have to provide a reference to an array for the entire output.

var_dump gives:
string(41) Mixer vol is currently set to 75:75


It also looks like \d{1,3}\. won't match anything in the output 
string

given by the command.





Thank you for that- that did it. I removed the \.

I am a little confused though; that regex was tested on several 
test sites

and was deemed accurate on them, and one of them actually supplied the
preg_match code. And if I run the command on a shell it actually 
outputs

exactly the right subject for the regex- not to mention it got printed
inadvertently (using system() ) via the php exactly the same. So I 
don't

think I missed it somehow.

What I have constantly seen come up (shell and php/html) is: Mixer 
vol is

currently set to 75:75. (including the period)

Don't get me wrong- you guys make sense; my system doesn't. I need 
to get to
the bottom of this so I can ensure my code will port well. I don't 
want to

get it all working and find it breaks when I run it on another system,
albeit same OS (FreeBSD). Could be updates or variations of releases.

Just to check again, I ran the command on the shell again and sure 
enough
the period is no longer there- but I can't for the life of me 
figure out
when that changed as this code has never worked (and yes, I added 
in the \.
to match the end of line because it originally wasn't working). 
Another

great mystery? Weird... :)

Thanks again guys.

The regex is a valid regex. It's just useless for the data you are 
providing it.


I'm wondering what is missing from your output? The var_dump says the
text is a 41 character string, but the data you provided only has 36
characters in it.

What elements of the string do you want to capture?

/:(\d++)/ would catch the number after the :




Apologies for the delay.

That works, except it will catch all instances. I need it to catch 
the last number specifically and not the period. The output will also 
output a previous and new reading- I need the new reading. And I also 
need to allow for the possibility of a period. So here's what I 
have:


/(\d++)[^.]?$

Which works as long as there is no period at the end. I just can't 
seem to get my head around it. I need a guru... :)


Did you miss the : at the beginning of RIchard's suggested regex? 
/:(\d++)/ would gather up all digits following a :. If the output 
from the mixer command is always something like dd:dd (irrespective of 
trailing period), the regex above would always return the second set 
of digits.



Sorry I probably didn't make it clear. The output can be the above or 
Setting the mixer vol from 70:70 to 75:75. Hence the $ for end of 
line. So I obviously need the last number (75) and nothing else.


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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-12-03 Thread Richard Quadling
On 3 December 2010 11:13, Da Rock php-l...@herveybayaustralia.com.au wrote:
 On 12/03/10 16:33, Tamara Temple wrote:

 On Dec 2, 2010, at 11:33 PM, Da Rock wrote:

 On 11/29/10 09:10, Richard Quadling wrote:

 On 27 November 2010 04:45, Da Rockphp-l...@herveybayaustralia.com.au
  wrote:

 On 11/27/10 13:51, Tamara Temple wrote:

 On Nov 26, 2010, at 7:28 PM, Da Rock wrote:


 On 11/27/10 00:57, Richard Quadling wrote:

 On 26 November 2010 00:07, Da
 Rockphp-l...@herveybayaustralia.com.au
  wrote:


 preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' .
 $command),$matches)


 Can you ...

 var_dump(exec($mixer . ' ' . $command));

 I wonder if the output includes a new line which you are not
 accounting for in the regex.



 Haven't tried yet, but isn't that what $ is for? End of line?



 $ matches end of line, but since your last match expression is to
 match
 explicitly the character '.' before end of line, and there's a
 newline, it
 won't match. Again, use trim() to get rid of the newline character at
 the
 end of the string returned by exec(). Looking at the output or


 And exec only gives one line- the last line of the output of the
 command.
 You have to provide a reference to an array for the entire output.

 var_dump gives:
 string(41) Mixer vol is currently set to 75:75


 It also looks like \d{1,3}\. won't match anything in the output string
 given by the command.




 Thank you for that- that did it. I removed the \.

 I am a little confused though; that regex was tested on several test
 sites
 and was deemed accurate on them, and one of them actually supplied the
 preg_match code. And if I run the command on a shell it actually
 outputs
 exactly the right subject for the regex- not to mention it got printed
 inadvertently (using system() ) via the php exactly the same. So I
 don't
 think I missed it somehow.

 What I have constantly seen come up (shell and php/html) is: Mixer vol
 is
 currently set to 75:75. (including the period)

 Don't get me wrong- you guys make sense; my system doesn't. I need to
 get to
 the bottom of this so I can ensure my code will port well. I don't want
 to
 get it all working and find it breaks when I run it on another system,
 albeit same OS (FreeBSD). Could be updates or variations of releases.

 Just to check again, I ran the command on the shell again and sure
 enough
 the period is no longer there- but I can't for the life of me figure
 out
 when that changed as this code has never worked (and yes, I added in
 the \.
 to match the end of line because it originally wasn't working). Another
 great mystery? Weird... :)

 Thanks again guys.

 The regex is a valid regex. It's just useless for the data you are
 providing it.

 I'm wondering what is missing from your output? The var_dump says the
 text is a 41 character string, but the data you provided only has 36
 characters in it.

 What elements of the string do you want to capture?

 /:(\d++)/ would catch the number after the :



 Apologies for the delay.

 That works, except it will catch all instances. I need it to catch the
 last number specifically and not the period. The output will also output a
 previous and new reading- I need the new reading. And I also need to allow
 for the possibility of a period. So here's what I have:

 /(\d++)[^.]?$

 Which works as long as there is no period at the end. I just can't seem
 to get my head around it. I need a guru... :)

 Did you miss the : at the beginning of RIchard's suggested regex?
 /:(\d++)/ would gather up all digits following a :. If the output from the
 mixer command is always something like dd:dd (irrespective of trailing
 period), the regex above would always return the second set of digits.


 Sorry I probably didn't make it clear. The output can be the above or
 Setting the mixer vol from 70:70 to 75:75. Hence the $ for end of line. So
 I obviously need the last number (75) and nothing else.

(\d++)[^\d]*?$


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-12-03 Thread Richard Quadling
On 3 December 2010 11:13, Da Rock php-l...@herveybayaustralia.com.au wrote:
 On 12/03/10 16:33, Tamara Temple wrote:

 On Dec 2, 2010, at 11:33 PM, Da Rock wrote:

 On 11/29/10 09:10, Richard Quadling wrote:

 On 27 November 2010 04:45, Da Rockphp-l...@herveybayaustralia.com.au
  wrote:

 On 11/27/10 13:51, Tamara Temple wrote:

 On Nov 26, 2010, at 7:28 PM, Da Rock wrote:


 On 11/27/10 00:57, Richard Quadling wrote:

 On 26 November 2010 00:07, Da
 Rockphp-l...@herveybayaustralia.com.au
  wrote:


 preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' .
 $command),$matches)


 Can you ...

 var_dump(exec($mixer . ' ' . $command));

 I wonder if the output includes a new line which you are not
 accounting for in the regex.



 Haven't tried yet, but isn't that what $ is for? End of line?



 $ matches end of line, but since your last match expression is to
 match
 explicitly the character '.' before end of line, and there's a
 newline, it
 won't match. Again, use trim() to get rid of the newline character at
 the
 end of the string returned by exec(). Looking at the output or


 And exec only gives one line- the last line of the output of the
 command.
 You have to provide a reference to an array for the entire output.

 var_dump gives:
 string(41) Mixer vol is currently set to 75:75


 It also looks like \d{1,3}\. won't match anything in the output string
 given by the command.




 Thank you for that- that did it. I removed the \.

 I am a little confused though; that regex was tested on several test
 sites
 and was deemed accurate on them, and one of them actually supplied the
 preg_match code. And if I run the command on a shell it actually
 outputs
 exactly the right subject for the regex- not to mention it got printed
 inadvertently (using system() ) via the php exactly the same. So I
 don't
 think I missed it somehow.

 What I have constantly seen come up (shell and php/html) is: Mixer vol
 is
 currently set to 75:75. (including the period)

 Don't get me wrong- you guys make sense; my system doesn't. I need to
 get to
 the bottom of this so I can ensure my code will port well. I don't want
 to
 get it all working and find it breaks when I run it on another system,
 albeit same OS (FreeBSD). Could be updates or variations of releases.

 Just to check again, I ran the command on the shell again and sure
 enough
 the period is no longer there- but I can't for the life of me figure
 out
 when that changed as this code has never worked (and yes, I added in
 the \.
 to match the end of line because it originally wasn't working). Another
 great mystery? Weird... :)

 Thanks again guys.

 The regex is a valid regex. It's just useless for the data you are
 providing it.

 I'm wondering what is missing from your output? The var_dump says the
 text is a 41 character string, but the data you provided only has 36
 characters in it.

 What elements of the string do you want to capture?

 /:(\d++)/ would catch the number after the :



 Apologies for the delay.

 That works, except it will catch all instances. I need it to catch the
 last number specifically and not the period. The output will also output a
 previous and new reading- I need the new reading. And I also need to allow
 for the possibility of a period. So here's what I have:

 /(\d++)[^.]?$

 Which works as long as there is no period at the end. I just can't seem
 to get my head around it. I need a guru... :)

 Did you miss the : at the beginning of RIchard's suggested regex?
 /:(\d++)/ would gather up all digits following a :. If the output from the
 mixer command is always something like dd:dd (irrespective of trailing
 period), the regex above would always return the second set of digits.


 Sorry I probably didn't make it clear. The output can be the above or
 Setting the mixer vol from 70:70 to 75:75. Hence the $ for end of line. So
 I obviously need the last number (75) and nothing else.

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



Get the last number.

(\d++)[^\d]*?$

Options: case insensitive; ^ and $ match at line breaks

Match the regular expression below and capture its match into
backreference number 1 «(\d++)»
   Match a single digit 0..9 «\d++»
  Between one and unlimited times, as many times as possible,
without giving back (possessive) «++»
Match a single character that is not a digit 0..9 «[^\d]*?»
   Between zero and unlimited times, as few times as possible,
expanding as needed (lazy) «*?»
Assert position at the end of a line (at the end of the string or
before a line break character) «$»


Created with RegexBuddy


if (preg_match('/(\d++)[^\d]*?$/sim', $subject, $matches)) {
$result = $matches[0];
} else {
$result = ;
}


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-12-02 Thread Da Rock

On 11/29/10 09:10, Richard Quadling wrote:

On 27 November 2010 04:45, Da Rockphp-l...@herveybayaustralia.com.au  wrote:
   

On 11/27/10 13:51, Tamara Temple wrote:
 

On Nov 26, 2010, at 7:28 PM, Da Rock wrote:

   

On 11/27/10 00:57, Richard Quadling wrote:
 

On 26 November 2010 00:07, Da Rockphp-l...@herveybayaustralia.com.au
  wrote:

   

preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command),$matches)

 

Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.


   

Haven't tried yet, but isn't that what $ is for? End of line?

 


$ matches end of line, but since your last match expression is to match
explicitly the character '.' before end of line, and there's a newline, it
won't match. Again, use trim() to get rid of the newline character at the
end of the string returned by exec(). Looking at the output or

   

And exec only gives one line- the last line of the output of the command.
You have to provide a reference to an array for the entire output.

var_dump gives:
string(41) Mixer vol is currently set to 75:75

 

It also looks like \d{1,3}\. won't match anything in the output string
given by the command.



   

Thank you for that- that did it. I removed the \.

I am a little confused though; that regex was tested on several test sites
and was deemed accurate on them, and one of them actually supplied the
preg_match code. And if I run the command on a shell it actually outputs
exactly the right subject for the regex- not to mention it got printed
inadvertently (using system() ) via the php exactly the same. So I don't
think I missed it somehow.

What I have constantly seen come up (shell and php/html) is: Mixer vol is
currently set to 75:75. (including the period)

Don't get me wrong- you guys make sense; my system doesn't. I need to get to
the bottom of this so I can ensure my code will port well. I don't want to
get it all working and find it breaks when I run it on another system,
albeit same OS (FreeBSD). Could be updates or variations of releases.

Just to check again, I ran the command on the shell again and sure enough
the period is no longer there- but I can't for the life of me figure out
when that changed as this code has never worked (and yes, I added in the \.
to match the end of line because it originally wasn't working). Another
great mystery? Weird... :)

Thanks again guys.
 

The regex is a valid regex. It's just useless for the data you are providing it.

I'm wondering what is missing from your output? The var_dump says the
text is a 41 character string, but the data you provided only has 36
characters in it.

What elements of the string do you want to capture?

/:(\d++)/ would catch the number after the :


   

Apologies for the delay.

That works, except it will catch all instances. I need it to catch the 
last number specifically and not the period. The output will also output 
a previous and new reading- I need the new reading. And I also need to 
allow for the possibility of a period. So here's what I have:


/(\d++)[^.]?$

Which works as long as there is no period at the end. I just can't seem 
to get my head around it. I need a guru... :)


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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-12-02 Thread Tamara Temple


On Dec 2, 2010, at 11:33 PM, Da Rock wrote:


On 11/29/10 09:10, Richard Quadling wrote:
On 27 November 2010 04:45, Da Rockphp- 
l...@herveybayaustralia.com.au  wrote:



On 11/27/10 13:51, Tamara Temple wrote:


On Nov 26, 2010, at 7:28 PM, Da Rock wrote:



On 11/27/10 00:57, Richard Quadling wrote:

On 26 November 2010 00:07, Da Rockphp-l...@herveybayaustralia.com.au 


 wrote:


preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command), 
$matches)




Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.




Haven't tried yet, but isn't that what $ is for? End of line?




$ matches end of line, but since your last match expression is to  
match
explicitly the character '.' before end of line, and there's a  
newline, it
won't match. Again, use trim() to get rid of the newline  
character at the

end of the string returned by exec(). Looking at the output or


And exec only gives one line- the last line of the output of the  
command.

You have to provide a reference to an array for the entire output.

var_dump gives:
string(41) Mixer vol is currently set to 75:75


It also looks like \d{1,3}\. won't match anything in the output  
string

given by the command.





Thank you for that- that did it. I removed the \.

I am a little confused though; that regex was tested on several  
test sites
and was deemed accurate on them, and one of them actually supplied  
the
preg_match code. And if I run the command on a shell it actually  
outputs
exactly the right subject for the regex- not to mention it got  
printed
inadvertently (using system() ) via the php exactly the same. So I  
don't

think I missed it somehow.

What I have constantly seen come up (shell and php/html) is: Mixer  
vol is

currently set to 75:75. (including the period)

Don't get me wrong- you guys make sense; my system doesn't. I need  
to get to
the bottom of this so I can ensure my code will port well. I don't  
want to
get it all working and find it breaks when I run it on another  
system,
albeit same OS (FreeBSD). Could be updates or variations of  
releases.


Just to check again, I ran the command on the shell again and sure  
enough
the period is no longer there- but I can't for the life of me  
figure out
when that changed as this code has never worked (and yes, I added  
in the \.
to match the end of line because it originally wasn't working).  
Another

great mystery? Weird... :)

Thanks again guys.

The regex is a valid regex. It's just useless for the data you are  
providing it.


I'm wondering what is missing from your output? The var_dump says the
text is a 41 character string, but the data you provided only has 36
characters in it.

What elements of the string do you want to capture?

/:(\d++)/ would catch the number after the :




Apologies for the delay.

That works, except it will catch all instances. I need it to catch  
the last number specifically and not the period. The output will  
also output a previous and new reading- I need the new reading. And  
I also need to allow for the possibility of a period. So here's  
what I have:


/(\d++)[^.]?$

Which works as long as there is no period at the end. I just can't  
seem to get my head around it. I need a guru... :)


Did you miss the : at the beginning of RIchard's suggested regex? /: 
(\d++)/ would gather up all digits following a :. If the output from  
the mixer command is always something like dd:dd (irrespective of  
trailing period), the regex above would always return the second set  
of digits.



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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-28 Thread Richard Quadling
On 27 November 2010 04:45, Da Rock php-l...@herveybayaustralia.com.au wrote:
 On 11/27/10 13:51, Tamara Temple wrote:

 On Nov 26, 2010, at 7:28 PM, Da Rock wrote:

 On 11/27/10 00:57, Richard Quadling wrote:

 On 26 November 2010 00:07, Da Rockphp-l...@herveybayaustralia.com.au
  wrote:

 preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command),$matches)

 Can you ...

 var_dump(exec($mixer . ' ' . $command));

 I wonder if the output includes a new line which you are not
 accounting for in the regex.


 Haven't tried yet, but isn't that what $ is for? End of line?



 $ matches end of line, but since your last match expression is to match
 explicitly the character '.' before end of line, and there's a newline, it
 won't match. Again, use trim() to get rid of the newline character at the
 end of the string returned by exec(). Looking at the output or

 And exec only gives one line- the last line of the output of the command.
 You have to provide a reference to an array for the entire output.

 var_dump gives:
 string(41) Mixer vol is currently set to 75:75


 It also looks like \d{1,3}\. won't match anything in the output string
 given by the command.



 Thank you for that- that did it. I removed the \.

 I am a little confused though; that regex was tested on several test sites
 and was deemed accurate on them, and one of them actually supplied the
 preg_match code. And if I run the command on a shell it actually outputs
 exactly the right subject for the regex- not to mention it got printed
 inadvertently (using system() ) via the php exactly the same. So I don't
 think I missed it somehow.

 What I have constantly seen come up (shell and php/html) is: Mixer vol is
 currently set to 75:75. (including the period)

 Don't get me wrong- you guys make sense; my system doesn't. I need to get to
 the bottom of this so I can ensure my code will port well. I don't want to
 get it all working and find it breaks when I run it on another system,
 albeit same OS (FreeBSD). Could be updates or variations of releases.

 Just to check again, I ran the command on the shell again and sure enough
 the period is no longer there- but I can't for the life of me figure out
 when that changed as this code has never worked (and yes, I added in the \.
 to match the end of line because it originally wasn't working). Another
 great mystery? Weird... :)

 Thanks again guys.

The regex is a valid regex. It's just useless for the data you are providing it.

I'm wondering what is missing from your output? The var_dump says the
text is a 41 character string, but the data you provided only has 36
characters in it.

What elements of the string do you want to capture?

/:(\d++)/ would catch the number after the :


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Richard Quadling
On 26 November 2010 00:07, Da Rock php-l...@herveybayaustralia.com.au wrote:
 preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command), $matches)

Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Tamara Temple


On Nov 25, 2010, at 6:07 PM, Da Rock wrote:
preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command),  
$matches)


it looks like you're failing to account for the newline that comes  
back in a command execution. Add trim() around the exec() call and try  
again.


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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Da Rock

On 11/27/10 00:57, Richard Quadling wrote:

On 26 November 2010 00:07, Da Rockphp-l...@herveybayaustralia.com.au  wrote:
   

preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command),$matches)
 

Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.

   

Haven't tried yet, but isn't that what $ is for? End of line?

And exec only gives one line- the last line of the output of the 
command. You have to provide a reference to an array for the entire output.


var_dump gives:
string(41) Mixer vol is currently set to 75:75

Any thoughts?

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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Tamara Temple


On Nov 26, 2010, at 7:28 PM, Da Rock wrote:


On 11/27/10 00:57, Richard Quadling wrote:
On 26 November 2010 00:07, Da Rockphp- 
l...@herveybayaustralia.com.au  wrote:


preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command), 
$matches)



Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.



Haven't tried yet, but isn't that what $ is for? End of line?




$ matches end of line, but since your last match expression is to  
match explicitly the character '.' before end of line, and there's a  
newline, it won't match. Again, use trim() to get rid of the newline  
character at the end of the string returned by exec(). Looking at the  
output or


And exec only gives one line- the last line of the output of the  
command. You have to provide a reference to an array for the entire  
output.


var_dump gives:
string(41) Mixer vol is currently set to 75:75



It also looks like \d{1,3}\. won't match anything in the output string  
given by the command.




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



Re: [PHP] preg_match fails to resolve variable as a subject

2010-11-26 Thread Da Rock

On 11/27/10 13:51, Tamara Temple wrote:


On Nov 26, 2010, at 7:28 PM, Da Rock wrote:


On 11/27/10 00:57, Richard Quadling wrote:
On 26 November 2010 00:07, Da 
Rockphp-l...@herveybayaustralia.com.au  wrote:


preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . 
$command),$matches)



Can you ...

var_dump(exec($mixer . ' ' . $command));

I wonder if the output includes a new line which you are not
accounting for in the regex.



Haven't tried yet, but isn't that what $ is for? End of line?




$ matches end of line, but since your last match expression is to 
match explicitly the character '.' before end of line, and there's a 
newline, it won't match. Again, use trim() to get rid of the newline 
character at the end of the string returned by exec(). Looking at the 
output or


And exec only gives one line- the last line of the output of the 
command. You have to provide a reference to an array for the entire 
output.


var_dump gives:
string(41) Mixer vol is currently set to 75:75



It also looks like \d{1,3}\. won't match anything in the output string 
given by the command.





Thank you for that- that did it. I removed the \.

I am a little confused though; that regex was tested on several test 
sites and was deemed accurate on them, and one of them actually supplied 
the preg_match code. And if I run the command on a shell it actually 
outputs exactly the right subject for the regex- not to mention it got 
printed inadvertently (using system() ) via the php exactly the same. So 
I don't think I missed it somehow.


What I have constantly seen come up (shell and php/html) is: Mixer vol 
is currently set to 75:75. (including the period)


Don't get me wrong- you guys make sense; my system doesn't. I need to 
get to the bottom of this so I can ensure my code will port well. I 
don't want to get it all working and find it breaks when I run it on 
another system, albeit same OS (FreeBSD). Could be updates or variations 
of releases.


Just to check again, I ran the command on the shell again and sure 
enough the period is no longer there- but I can't for the life of me 
figure out when that changed as this code has never worked (and yes, I 
added in the \. to match the end of line because it originally wasn't 
working). Another great mystery? Weird... :)


Thanks again guys.

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



[PHP] preg_match fails to resolve variable as a subject

2010-11-25 Thread Da Rock
I have been scratching on this for some time now, and throughout I've 
been trying subscribe to this list.


Pardon if this is a stupid question, but I googled for days on this and 
still couldn't get it to work.


Is there a known issue with php's preg_match? I can get it to work on a 
string directly, but if I use a variable it fails with no match. 
pcretest works, and the variable prints correctly. I also used a number 
of online regex testers and worked, one gave me the basis of the code.


I can only post a piece of the code as I don't wish to offend, give you 
some clue as to how far strung I am.


preg_match(/(\d{1,3})(\.)$/, exec($mixer . ' ' . $command), $matches)

I've separated the command so it outputs to a variable, and placed the 
variable as the subject with the same result. It also fails with 
system() as well.


A little light on the subject (pardon the pun :) ) would be very 
helpful. I know its very simple code, but its just a base to something else.



Cheers

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



[PHP] preg_match? Or something else?

2010-04-02 Thread Ashley M. Kirchner
I have an array that's created as follows:

 

$string = 73G146C   311- 309.1C;

$arr = preg_split(/[\s]+/, $string);

 

Now I need to take each element in that array, and break them up even
further so that I get:

 

73G= 73 and G

146C   = 146 and C

311-   = 311 and -

309.1C = 309, 1, and C  (notice 3 elements here)

 

I'm having a hard time trying to figure out what the proper regex would be
for this, or whether that's the right thing to do.  So far I've gotten this:

 

  preg_match(/^(?Plocation\d+)(?Pletter[A-Z-])/, $item, $matches);

  print_r($matches);

 

Which gives me:

 

Array

(

[0] = 73G

[location] = 73

[1] = 73

[letter] = G

[2] = G

)

Array

(

[0] = 146C

[location] = 146

[1] = 146

[letter] = C

[2] = C

)

Array

(

[0] = 311-

[location] = 311

[1] = 311

[letter] = -

[2] = -

)

Array

(

)

 

 

However that's as far as it goes.  For the other number it returns an empty
array and I know why, the decimal point.   Now I can evaluate each $item
every time, see if they contain a decimal point, and pass it to a different
regex string, but that seems rather inefficient to me.  So how can I do this
all in one fell swoop?

 

Anyone want to take a stab at it?



Re: [PHP] preg_match? Or something else?

2010-04-02 Thread Jim Lucas
Ashley M. Kirchner wrote:
 I have an array that's created as follows:
 
  
 
 $string = 73G146C   311- 309.1C;
 
 $arr = preg_split(/[\s]+/, $string);
 
  
 
 Now I need to take each element in that array, and break them up even
 further so that I get:
 
  
 
 73G= 73 and G
 
 146C   = 146 and C
 
 311-   = 311 and -
 
 309.1C = 309, 1, and C  (notice 3 elements here)
 
  
 
 I'm having a hard time trying to figure out what the proper regex would be
 for this, or whether that's the right thing to do.  So far I've gotten this:
 
  
 
   preg_match(/^(?Plocation\d+)(?Pletter[A-Z-])/, $item, $matches);
 
   print_r($matches);
 
  
 
 Which gives me:
 
  
 
 Array
 
 (
 
 [0] = 73G
 
 [location] = 73
 
 [1] = 73
 
 [letter] = G
 
 [2] = G
 
 )
 
 Array
 
 (
 
 [0] = 146C
 
 [location] = 146
 
 [1] = 146
 
 [letter] = C
 
 [2] = C
 
 )
 
 Array
 
 (
 
 [0] = 311-
 
 [location] = 311
 
 [1] = 311
 
 [letter] = -
 
 [2] = -
 
 )
 
 Array
 
 (
 
 )
 
 However that's as far as it goes.  For the other number it returns an empty
 array and I know why, the decimal point.   Now I can evaluate each $item
 every time, see if they contain a decimal point, and pass it to a different
 regex string, but that seems rather inefficient to me.  So how can I do this
 all in one fell swoop?
 
 Anyone want to take a stab at it?
 
 

Conditionals are your friend!

plaintext?php

$string = 73G146C   311- 309.1C;

$arr = preg_split(/[\s]+/, $string);

print_r($arr);

foreach ( $arr AS $item ) {
preg_match('|^(?Plocation\d+)\.?(?Pdecimal\d*)(?Pletter[A-Z-])|',
   $item,
   $matches);

print_r($matches);
}

?

-- 
Jim Lucas
NOC Manager
541-323-9113
BendTel, Inc.
http://www.bendtel.com

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



Re: [PHP] preg_match? Or something else?

2010-04-02 Thread Nathan Rixham
Jim Lucas wrote:
 Ashley M. Kirchner wrote:
 I have an array that's created as follows:

  

 $string = 73G146C   311- 309.1C;


 Anyone want to take a stab at it?


 
 Conditionals are your friend!
 
 plaintext?php
 
 $string = 73G146C   311- 309.1C;
 
 $arr = preg_split(/[\s]+/, $string);
 
 print_r($arr);
 
 foreach ( $arr AS $item ) {
   preg_match('|^(?Plocation\d+)\.?(?Pdecimal\d*)(?Pletter[A-Z-])|',
$item,
$matches);
 
   print_r($matches);
 }
 
 ?
 

or w/ preg_match_all:

?php
$regex = '/(([0-9]+)([^0-9])((?:[0-9]|\s+)))/';
$string = 73G146C   311- 309.1C;
preg_match_all( $regex , $string , $matches );
print_r( $matches )

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



[PHP] preg_match()

2009-09-09 Thread Jan Reiter
Good Afternoon.

 

This shouldn't be too complicated, but I can't come up with a solution for
the problem right now. It's about RegEx in PHP (5.2)

 

Is there a way to capture ALL sub elements of an expression like
preg_match('@a(?[0-9])*b@' ,a2345678b , $matches);   ??

This would produce (below) whereas I'd like to get all the elements (2-8) as
an array entry each . ([1]=2, [2]=3 .)

 

Result:

array(2) {

  [0]=

  array(1) {

[0]=

string(9) a2345678b

  }

  [1]=

  array(1) {

[0]=

string(1) 8

  }

}

 

preg_match_all doesn't do the trick. 

 

The Expression I want to use is

 

@prim_states[\s]*\((?num[0-9\s]*)(prim_state[\s]*\((?flag[a-fA-F0-9\s]*)
tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@

 

as I'm trying to parse a 3d Model File, that contains data in the form of

 

prim_states ( 51

   prim_state (  2

   tex_idxs ( 1 2 ) 0 3 0 0 1

   )

   prim_state (  3

   tex_idxs ( 1 2 ) 0 0 1 0 1

   )

   prim_state (  3

   tex_idxs ( 1 2 ) 0 4 1 0 1

   )

 [.]

)

 

Thank You!

 

Regards,

Jan

 

 

 



Re: [PHP] preg_match()

2009-09-09 Thread Ashley Sheridan
On Wed, 2009-09-09 at 18:18 +0200, Jan Reiter wrote:
 Good Afternoon.
 
  
 
 This shouldn't be too complicated, but I can't come up with a solution for
 the problem right now. It's about RegEx in PHP (5.2)
 
  
 
 Is there a way to capture ALL sub elements of an expression like
 preg_match('@a(?[0-9])*b@' ,a2345678b , $matches);   ??
 
 This would produce (below) whereas I'd like to get all the elements (2-8) as
 an array entry each . ([1]=2, [2]=3 .)
 
  
 
 Result:
 
 array(2) {
 
   [0]=
 
   array(1) {
 
 [0]=
 
 string(9) a2345678b
 
   }
 
   [1]=
 
   array(1) {
 
 [0]=
 
 string(1) 8
 
   }
 
 }
 
  
 
 preg_match_all doesn't do the trick. 
 
  
 
 The Expression I want to use is
 
  
 
 @prim_states[\s]*\((?num[0-9\s]*)(prim_state[\s]*\((?flag[a-fA-F0-9\s]*)
 tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@
 
  
 
 as I'm trying to parse a 3d Model File, that contains data in the form of
 
  
 
 prim_states ( 51
 
prim_state (  2
 
tex_idxs ( 1 2 ) 0 3 0 0 1
 
)
 
prim_state (  3
 
tex_idxs ( 1 2 ) 0 0 1 0 1
 
)
 
prim_state (  3
 
tex_idxs ( 1 2 ) 0 4 1 0 1
 
)
 
  [.]
 
 )
 
  
 
 Thank You!
 
  
 
 Regards,
 
 Jan
 
  
If your example is indicative of what you need, then couldn't you just
loop through all the elements inside of the match as it will be a
contiguous string of numbers.

Thanks,
Ash
http://www.ashleysheridan.co.uk




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



RE: [PHP] preg_match()

2009-09-09 Thread Jan Reiter
Not quite, I'm sorry. As the outer expression prim_states( [...] ) captures,
the repetitive elements inside prim_state( [...] ) overwrite each other in
the matches array. 
Of course I could get the first entry in matches, and search it again with
preg_match_all(), but that is what I'm trying to avoid. But maybe that's
what I have to after all if there is no other way.

Thanks  Regards,
Jan

-Original Message-
From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Wednesday, September 09, 2009 6:21 PM
To: Jan Reiter
Cc: php-general@lists.php.net
Subject: Re: [PHP] preg_match()

On Wed, 2009-09-09 at 18:18 +0200, Jan Reiter wrote:
 Good Afternoon.
 
  
 
 This shouldn't be too complicated, but I can't come up with a solution for
 the problem right now. It's about RegEx in PHP (5.2)
 
  
 
 Is there a way to capture ALL sub elements of an expression like
 preg_match('@a(?[0-9])*b@' ,a2345678b , $matches);   ??
 
 This would produce (below) whereas I'd like to get all the elements (2-8)
as
 an array entry each . ([1]=2, [2]=3 .)
 
  
 
 Result:
 
 array(2) {
 
   [0]=
 
   array(1) {
 
 [0]=
 
 string(9) a2345678b
 
   }
 
   [1]=
 
   array(1) {
 
 [0]=
 
 string(1) 8
 
   }
 
 }
 
  
 
 preg_match_all doesn't do the trick. 
 
  
 
 The Expression I want to use is
 
  
 

@prim_states[\s]*\((?num[0-9\s]*)(prim_state[\s]*\((?flag[a-fA-F0-9\s]*)
 tex_idxs[\s]*\(([0-9\s]*)\)([0-9\s]*)\)[\s]*)*\)@
 
  
 
 as I'm trying to parse a 3d Model File, that contains data in the form of
 
  
 
 prim_states ( 51
 
prim_state (  2
 
tex_idxs ( 1 2 ) 0 3 0 0 1
 
)
 
prim_state (  3
 
tex_idxs ( 1 2 ) 0 0 1 0 1
 
)
 
prim_state (  3
 
tex_idxs ( 1 2 ) 0 4 1 0 1
 
)
 
  [.]
 
 )
 
  
 
 Thank You!
 
  
 
 Regards,
 
 Jan
 
  
If your example is indicative of what you need, then couldn't you just
loop through all the elements inside of the match as it will be a
contiguous string of numbers.

Thanks,
Ash
http://www.ashleysheridan.co.uk




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Eingehende eMail ist virenfrei.
Von AVG überprüft - www.avg.de 
Version: 8.5.409 / Virendatenbank: 270.13.71/2336 - Ausgabedatum: 09/08/09
20:45:00 


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



RE: [PHP] preg_match()

2009-09-09 Thread Jan Reiter
Thanks! Thats about what I'm doing right now. 

function parse_prim_states($in)
{
preg_match('@prim_states[\s]*\((?number[0-9\s]*)@' ,$in ,
$matches);
$this-num_prim_states  = (int)$matches['number'];


preg_match_all('@prim_state[\s]*\((?flag1[a-fA-F0-9\s]*)tex_idxs[\s]*\((?
texidx[0-9\s]*)\)(?flag2[0-9\s]*)\)@' ,$in , $matches);

for($i=0;$i$this-num_prim_states;$i++)
{

$this-add_prim_state($matches['flag1'][$i],$matches['flag2'][$i],$matches['
texid'][$i]);
}

unset($matches);

return true;
}

Regards

-Original Message-
From: Shawn McKenzie [mailto:nos...@mckenzies.net] 
Sent: Wednesday, September 09, 2009 7:57 PM
To: Jan Reiter
Cc: php-general@lists.php.net
Subject: [PHP] Re: preg_match()

Jan Reiter wrote:
 Good Afternoon.
 
  
 
 This shouldn't be too complicated, but I can't come up with a solution for
 the problem right now. It's about RegEx in PHP (5.2)
 
  
 
 Is there a way to capture ALL sub elements of an expression like
 preg_match('@a(?[0-9])*b@' ,a2345678b , $matches);   ??
 
 This would produce (below) whereas I'd like to get all the elements (2-8)
as
 an array entry each . ([1]=2, [2]=3 .)
 

AFAIK, you would need to know how many digits are there and use that
many capture groups (), because you only have one capture group which
will be overwritten each iteration.  An alternative for your simple
example above would be to do:

preg_match('@a([0-9]+)b@' ,a2345678b , $matches);

--then--

print_r(str_split($matches[1]));

To do this multiple times in a large string you would need:

preg_match_all('@a([0-9]+)b@' ,a2345678b , $matches);

foreach($matches[1] as $match) {
print_r(str_split($match));
}

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Eingehende eMail ist virenfrei.
Von AVG überprüft - www.avg.de 
Version: 8.5.409 / Virendatenbank: 270.13.71/2336 - Ausgabedatum: 09/09/09
06:53:00 


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



[PHP] preg_match doesn't match Greek

2009-09-01 Thread Thodoris

Hi gang,
   I am trying to make a form validation using preg_match and it fails. 
I think it is because the input is in Greek. I have made this script:


$str = ΕΕΝ 5196;
$pattern = /^[[:alnum:]\s\-\,]*$/u;

echo 'pre';
print preg_match($pattern,$str,$matches).\n;
print_r($matches);

to test preg_match's behavior and when the above string has Latin 
characters the pattern matches when it's in greek. Can someone explain 
this? Is there a workaround?


PS all are in UTF-8.

--
Thodoris


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



RE: [PHP] preg_match too greedy

2009-07-31 Thread Ford, Mike
 -Original Message-
 From: b [mailto:p...@logi.ca]
 Sent: 30 July 2009 03:17
 
 
 
  echo (preg_match($pattern, $test) != false)
 
  The  != false  here is redundant.
 
 Understood. But what you think is redundancy is, to me, clarity in
 programming. I happen to think that boolean tests shouldn't ride on
 whether or not an array returned from a function is empty or not (or
 a
 freaking boolean). If what I'm looking for is a false then that's
 what
 I'll test for.

Well, then, by that logic you should be testing separately for ===FALSE and 
===0, since the former means an error occurred, whilst the latter means the 
pattern was ok but didn't match.  If the pattern finds a match, the return 
value is 1 (not TRUE).


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730


  


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] preg_match too greedy

2009-07-30 Thread Ben Dunlap
 echo (preg_match($pattern, $test) != false)

 The  != false  here is redundant.
 
 Understood. But what you think is redundancy is, to me, clarity in
 programming. I happen to think that boolean tests shouldn't ride on
 whether or not an array returned from a function is empty or not (or a
 freaking boolean). If what I'm looking for is a false then that's what
 I'll test for.

Fair enough, but in that case I think you want !== false. The expression you
have -- ($x != false) -- will be true whether $x is 0, NULL, an empty string,
an empty array, or actually FALSE.

But $x !== false will only be true in the last case.

Ben

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



Re: [PHP] preg_match too greedy

2009-07-30 Thread Ben Dunlap
Ben Dunlap wrote:
 have -- ($x != false) -- will be true whether $x is 0, NULL, an empty 
 string,
[8]
 But $x !== false will only be true in the last case.

Sorry, replace be true with be false above.

-Ben

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



[PHP] preg_match too greedy

2009-07-29 Thread b
I'm trying to figure out how to test if a string matches *exactly* 
another string, using a regexp pattern. The manual says that ereg() is 
deprecated (in favour of what?) and preg_match() is giving me trouble. 
The problem is that I'm passing the end-of-line delimiter ($) but it 
seems to be ignored. An example:


-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';

echo ${url} :: ${test}\n;

echo (preg_match($pattern, $test) != false)
? 'match'
: 'no match';
-- snip --

I expected 'no match' but get 'match'.

The reason for the (/)? is to allow for a trailing slash. I've added a 
'$' to specify that I want to test for the exact string. However, 
preg_match() tests for the existence of a string and appears to ignore 
the '$'.


How do I do this?

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Ben Dunlap
Jim Lucas wrote:
 I expected 'no match' but get 'match'.
[8]
 cut/paste your code and it works for me.

Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?

If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:

 $url = '/foo(/)?';

I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.

 echo (preg_match($pattern, $test) != false)

The  != false  here is redundant. Combined with the ternary operator, the
logical switchbacks make me a little dizzy (especially this close to lunchtime).

Ben

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Jim Lucas
Ben Dunlap wrote:
 Jim Lucas wrote:
 I expected 'no match' but get 'match'.
 [8]
 cut/paste your code and it works for me.
 
 Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
 version do you have?

PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
  with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project


 
 If I might suggest a couple of simplifications that would make it easier to
 follow/troubleshoot:
 
 $url = '/foo(/)?';
 
 I don't think you need parentheses around your second forward-slash. If you 
 had
 multiple characters that were optional you'd want to group them in 
 parentheses,
 but here I think it just makes the regex harder to read.
 
 echo (preg_match($pattern, $test) != false)
 
 The  != false  here is redundant. Combined with the ternary operator, the
 logical switchbacks make me a little dizzy (especially this close to 
 lunchtime).
 
 Ben
 



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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Daniel Kolbo
Jim Lucas wrote:
 Ben Dunlap wrote:
 Jim Lucas wrote:
 I expected 'no match' but get 'match'.
 [8]
 cut/paste your code and it works for me.
 Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
 version do you have?
 
 PHP 5.2.5 with Suhosin-Patch 0.9.6.2 (cli) (built: Mar 11 2008 13:08:50)
 Copyright (c) 1997-2007 The PHP Group
 Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
   with Suhosin v0.9.20, Copyright (c) 2002-2006, by Hardened-PHP Project
 
 
 If I might suggest a couple of simplifications that would make it easier to
 follow/troubleshoot:

 $url = '/foo(/)?';
 I don't think you need parentheses around your second forward-slash. If you 
 had
 multiple characters that were optional you'd want to group them in 
 parentheses,
 but here I think it just makes the regex harder to read.

 echo (preg_match($pattern, $test) != false)
 The  != false  here is redundant. Combined with the ternary operator, the
 logical switchbacks make me a little dizzy (especially this close to 
 lunchtime).

 Ben

 
 
 
code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.

Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'
This time preg_match fails due to the end of line anchor.
hth
dK
`

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 02:07 PM, Jim Lucas wrote:

b wrote:

I'm trying to figure out how to test if a string matches *exactly*
another string, using a regexp pattern. The manual says that ereg() is
deprecated (in favour of what?) and preg_match() is giving me trouble.
The problem is that I'm passing the end-of-line delimiter ($) but it
seems to be ignored. An example:

-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';

echo ${url} :: ${test}\n;

echo (preg_match($pattern, $test) != false)
 ? 'match'
 : 'no match';
-- snip --

I expected 'no match' but get 'match'.

The reason for the (/)? is to allow for a trailing slash. I've added a
'$' to specify that I want to test for the exact string. However,
preg_match() tests for the existence of a string and appears to ignore
the '$'.

How do I do this?



cut/paste your code and it works for me.

Jim Lucas



Works, meaning you get 'match', or 'no match'? It should be the latter, 
but I'm seeing the former.


I'm using 5.2.9, btw.

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 03:03 PM, Ben Dunlap wrote:

Jim Lucas wrote:

I expected 'no match' but get 'match'.

[8]

cut/paste your code and it works for me.


Works for me as well. I get 'no match' from PHP 5.1.2, 5.2.6, and 5.2.8. What
version do you have?


5.2.9


If I might suggest a couple of simplifications that would make it easier to
follow/troubleshoot:


$url = '/foo(/)?';


I don't think you need parentheses around your second forward-slash. If you had
multiple characters that were optional you'd want to group them in parentheses,
but here I think it just makes the regex harder to read.


Really? I think it makes it crystal clear that it's the '/' that is 
optional. In any case, it makes no difference.





echo (preg_match($pattern, $test) != false)


The  != false  here is redundant.


Understood. But what you think is redundancy is, to me, clarity in 
programming. I happen to think that boolean tests shouldn't ride on 
whether or not an array returned from a function is empty or not (or a 
freaking boolean). If what I'm looking for is a false then that's what 
I'll test for.



Combined with the ternary operator, the logical switchbacks make me a

 little dizzy (especially this close to lunchtime).




Oh, you're one of those people who can't stand the sight of a ternary 
operator. Buck up, son, it's good for ya ;-)


(Seriously: I don't understand why ternaries freak some people out. It's 
plain as day!)



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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 07:48 PM, Daniel Kolbo wrote:


code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.


The forward slash shouldn't be an issue as the delimiter is '%'. The 
full pattern is:


%^/foo/?$%U



Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'


But the string happens to start with a forward slash.


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



Re: [PHP] preg_match too greedy

2009-07-29 Thread Daniel Kolbo
b wrote:
 On 07/29/2009 07:48 PM, Daniel Kolbo wrote:

 code works (no match) for me too on php 5.2.6 build date May 2 2008
 18:01:20 with dumbdows NT.

 preg_match fails but for a reason other than what I think you may be
 expecting.  It fails b/c of the first forwards slash in $url.  The regex
 engine doesn't even get past the second character let alone reaching the
 end of line anchor.
 
 The forward slash shouldn't be an issue as the delimiter is '%'. The
 full pattern is:
 
 %^/foo/?$%U
 
 
 Also, your code works (no match) with this first forward slash removed:
 $url = 'foo(/)?'
 
 But the string happens to start with a forward slash.
 
 
i am not talking about the delimiter
your pattern is:
%^/foo/?$%U
your test string is:
'foo/bar'

the first character of your pattern is a / and your first character of
your test string is an f.  They do not match.  The regex engine stops
after checking the first character.  This has nothing to do with
greediness or end of line anchors, but only with the first character
comparisons.

maybe what you wanted for your test string was
'/foo/bar'

This test string would then require your end of line anchor. Because the
end of line character does not match the b the engine stops.  No match.

This is consistent with the findings of others who replied to you.

Perhaps your regex engine has a different syntax for anchors.  For
example if your engine was seeing the carrot as a an exclusion operator
rather than being a beginning of line anchor and it was also, idk,
ignoring the dollar sign as your end of line anchor then you would get a
match.  But otherwise I would recommend you copy/paste the example you
provided and confirm that you still get a match.  Then i would confirm
your regex engine's anchor syntax.  Then, recompile your software
dK
`

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



Re: [PHP] preg_match too greedy

2009-07-29 Thread b

On 07/29/2009 11:18 PM, Daniel Kolbo wrote:

b wrote:

On 07/29/2009 07:48 PM, Daniel Kolbo wrote:

code works (no match) for me too on php 5.2.6 build date May 2 2008
18:01:20 with dumbdows NT.

preg_match fails but for a reason other than what I think you may be
expecting.  It fails b/c of the first forwards slash in $url.  The regex
engine doesn't even get past the second character let alone reaching the
end of line anchor.

The forward slash shouldn't be an issue as the delimiter is '%'. The
full pattern is:

%^/foo/?$%U



Also, your code works (no match) with this first forward slash removed:
$url = 'foo(/)?'

But the string happens to start with a forward slash.



i am not talking about the delimiter
your pattern is:
%^/foo/?$%U
your test string is:
'foo/bar'


AAARRRGG! Sorry, that's a typo! It should be:

$test = '/foo/bar';

I guess that explains a lot. For the record, I had to type that in 
because this latest version of Thunderbird crashes whenever I paste into 
it. (note to self: downgrade that, stat!)






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



[PHP] preg_match and multibyte

2009-04-09 Thread Merlin Morgenstern

Hello,

I am trying to extract a number out of a string that is in utf-8 and 
contains chines characters.


This unfortunatelly does not work:

preg_match('{(\d+)}', $details, $m);
$number = $m[1];

I also tried to utf8decode it, but still, no luck.

Does anybody know how to overcome this problem?

Regards, Merlin

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



Re: [PHP] preg_match and multibyte

2009-04-09 Thread tedd

At 4:18 PM +0200 4/9/09, Merlin Morgenstern wrote:

Hello,

I am trying to extract a number out of a string that is in utf-8 and 
contains chines characters.


This unfortunatelly does not work:

preg_match('{(\d+)}', $details, $m);
$number = $m[1];

I also tried to utf8decode it, but still, no luck.

Does anybody know how to overcome this problem?

Regards, Merlin


That's simple, there's no chines characters in Unicode.

Cheers,  :-)

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] preg_match and multibyte

2009-04-09 Thread Merlin Morgenstern



tedd wrote:

At 4:18 PM +0200 4/9/09, Merlin Morgenstern wrote:

Hello,

I am trying to extract a number out of a string that is in utf-8 and 
contains chines characters.


This unfortunatelly does not work:

preg_match('{(\d+)}', $details, $m);
$number = $m[1];

I also tried to utf8decode it, but still, no luck.

Does anybody know how to overcome this problem?

Regards, Merlin


That's simple, there's no chines characters in Unicode.

Cheers,  :-)

tedd



:-) sorry about my spelling. Chinese.
e.g.:
月租: 350元其

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



[PHP] preg_match and dates

2009-03-02 Thread Michael A. Peters

I have absolutely no control over the source file.

The source file is an xml file (er, sort of, it doesn't follow any 
particular DTD) and has a tag called VERBATIM_DATE in each record - 
looks to be required in their output as every record so far has it, but 
w/o a DTD hard to know - time of day, on the other hand, is not required 
and sometimes (usually) the tag missing.


Here's the beauty - VERBATIM_DATE in the same xml file uses multiple 
different formats. IE -


12 March 1945
14 Mar 1967
Apr 1999
12-03-2005
Before 1904
Winter or Spring 1977

etc.

It does seem that if there is a day, the day is always first - but 
sometimes it has a space as a delimiter, - as delimiter, and sometimes 
it has both - IE


10-15 Dec 1934
12 March-03 April 1956

What I'm trying to do is write a preg matches for each case I come 
across - if it matches the preg, it then parses according to the pattern 
to get me an acceptable -MM-DD (not sure how I'll deal with the 
season case yet ... but I'm serious, that kind of thing in there several 
times)


To at least get started though, is there a wildcard defined that says 
match a month?


IE

/^([0-9]{2})[\s-](MONTH_MATCH)[\s-]([0-9]{4,4}$/

where MONTH is some special magic that matches Mar March Apr April etc. ?

If you must know - it's data from a biology vertebrate museum. Thousands 
of records may match a given query. Most of them look fairly easily 
parsable and it does look like when a day is specified, it is always 
first and year is always last.


The data is needed by me, so I'm planning on having the script die if it 
comes across a date I don't have a regex to parse before it does 
anything so I can add appropriate regex as necessary, but damn - you'd 
think a vertebrate museum would have cleaned up their DB somewhat.


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



Re: [PHP] preg_match and dates

2009-03-02 Thread Per Jessen
Michael A. Peters wrote:

 What I'm trying to do is write a preg matches for each case I come
 across - if it matches the preg, it then parses according to the
 pattern to get me an acceptable -MM-DD (not sure how I'll deal
 with the season case yet ... but I'm serious, that kind of thing in
 there several times)
 
 To at least get started though, is there a wildcard defined that says
 match a month?
 
 IE
 
 /^([0-9]{2})[\s-](MONTH_MATCH)[\s-]([0-9]{4,4}$/
 
 where MONTH is some special magic that matches Mar March Apr April
 etc. ?

Just write one yourself. 



-- 
Per Jessen, Zürich (6.1°C)


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



Re: [PHP] preg_match and dates

2009-03-02 Thread Per Jessen

Michael A. Peters wrote:

This is what I have so far -

$pattern[] = /^([0-9]{1,2})[\s-]([A-Z][a-z]*)[\s-]([0-9]{4,4})$/i;
$clean[]   = \\3-\\2-\\1;

$pattern[] = /^([A-Z][a-z]*)[\s-]([0-9]{4,4})$/;
$clean[]   = \\2-\\1-01;

$foo = preg_replace($pattern, $clean, $verb_date);


If I were you, I'd write several regexes, one for each date format you 
wish to recognize.  It makes the regexes much easier to read, and you 
can still write sub-expressions for catching e.g. months and then reuse 
those in your main regexes.




/Per Jessen

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



Re: [PHP] preg_match and dates

2009-03-02 Thread Michael A. Peters

Per Jessen wrote:

Michael A. Peters wrote:


What I'm trying to do is write a preg matches for each case I come
across - if it matches the preg, it then parses according to the
pattern to get me an acceptable -MM-DD (not sure how I'll deal
with the season case yet ... but I'm serious, that kind of thing in
there several times)

To at least get started though, is there a wildcard defined that says
match a month?

IE

/^([0-9]{2})[\s-](MONTH_MATCH)[\s-]([0-9]{4,4}$/

where MONTH is some special magic that matches Mar March Apr April
etc. ?


Just write one yourself. 






This is what I have so far -

$pattern[] = /^([0-9]{1,2})[\s-]([A-Z][a-z]*)[\s-]([0-9]{4,4})$/i;
$clean[]   = \\3-\\2-\\1;

$pattern[] = /^([A-Z][a-z]*)[\s-]([0-9]{4,4})$/;
$clean[]   = \\2-\\1-01;

$foo = preg_replace($pattern, $clean, $verb_date);

That was enough for me to discover some collectors have two digit years 
and I can't differentiate 1902 from 2002 so I'll have to flag those and 
bug the curator to fix 'em.


I'd rather have ([A-Z][a-z]*) be replaced with something that makes sure 
it is a valid short or long month, writing one myself is not impossible 
but if there is a date wildcard (or a tried and proven pattern) that can 
match month built into php then it is better to use it, no?


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



[PHP] preg_match question...

2009-02-06 Thread bruce
hi...

trying to figure out the best approach to using preg_match to extract the
number from the follwing type of line...

 131646 sometext follows..

basically, i want to extract the number, without the text, but i have to be
able to match on the text

i've been playing with different preg_match regexs.. but i'm missing
something obvious!

thoughts/comments..


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



Re: [PHP] preg_match question...

2009-02-06 Thread Alpár Török
preg_match('/^([0-9]+) (.)+/',$sString,$aMatches);

Matches will be 1 = the number ; 2 = the text. The expression only matches
if there is any character after the space.  Not necessarily text, it might
be another number or special characters

2009/2/6 bruce bedoug...@earthlink.net

 hi...

 trying to figure out the best approach to using preg_match to extract the
 number from the follwing type of line...

  131646 sometext follows..

 basically, i want to extract the number, without the text, but i have to be
 able to match on the text

 i've been playing with different preg_match regexs.. but i'm missing
 something obvious!

 thoughts/comments..


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




-- 
Alpar Torok


Re: [PHP] preg_match question...

2009-02-06 Thread Jim Lucas
bruce wrote:
 hi...
 
 trying to figure out the best approach to using preg_match to extract the
 number from the follwing type of line...
 
  131646 sometext follows..
 
 basically, i want to extract the number, without the text, but i have to be
 able to match on the text
 
 i've been playing with different preg_match regexs.. but i'm missing
 something obvious!
 
 thoughts/comments..
 
 

Why don't you show us some of the attempts that you have tried that didn't work.

When you say that you need to match on some of the text, give us an example of 
the text that you are trying to match.

And give us examples of the input text you are trying to match to.

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] preg_match

2008-10-27 Thread Alex Chamberlain
Hi,

I don’t understand regular expressions at all – I will make an effort to
learn about them one day, but I need a solution today. I want to use the
__autoload function, but not for all my class only those that finish in
‘Controller’. So for instance,

‘ErrorController’ should load ‘errorcontroller.inc.php’
‘IndexController’ should load ‘indexcontroller.inc.php’
‘FooBar’ should NOT load anything whatsoever.

Can you help me write an __autoload function please??

Alex

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com 
Version: 8.0.175 / Virus Database: 270.8.3/1748 - Release Date: 27/10/2008
07:57


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



Re: [PHP] preg_match

2008-10-27 Thread Stut

On 27 Oct 2008, at 15:08, Alex Chamberlain wrote:
I don’t understand regular expressions at all – I will make an  
effort to
learn about them one day, but I need a solution today. I want to use  
the
__autoload function, but not for all my class only those that finish  
in

‘Controller’. So for instance,

‘ErrorController’ should load ‘errorcontroller.inc.php’
‘IndexController’ should load ‘indexcontroller.inc.php’
‘FooBar’ should NOT load anything whatsoever.

Can you help me write an __autoload function please??


Have you even tried it? This is not hard, and doesn't need to use any  
regular expressions at all.


We're not here to write code for you, we're here to help when you have  
problems. Try it, see how far you get and send us the code if/when you  
get stuck.


Unless you want to hire me to do it. My rates are pretty reasonable  
for simple stuff like this.


-Stut

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



RE: [PHP] preg_match

2008-10-27 Thread Alex Chamberlain
 -Original Message-
 From: Stut [mailto:[EMAIL PROTECTED]
 Sent: 27 October 2008 15:21
 To: Alex Chamberlain
 Cc: PHP General list
 Subject: Re: [PHP] preg_match
 
 On 27 Oct 2008, at 15:08, Alex Chamberlain wrote:
  I don’t understand regular expressions at all – I will make an
  effort to
  learn about them one day, but I need a solution today. I want to use
  the
  __autoload function, but not for all my class only those that finish
  in
  ‘Controller’. So for instance,
 
  ‘ErrorController’ should load ‘errorcontroller.inc.php’
  ‘IndexController’ should load ‘indexcontroller.inc.php’
  ‘FooBar’ should NOT load anything whatsoever.
 
  Can you help me write an __autoload function please??
 
 Have you even tried it? This is not hard, and doesn't need to use any
 regular expressions at all.
 
 We're not here to write code for you, we're here to help when you have
 problems. Try it, see how far you get and send us the code if/when you
 get stuck.
 
 Unless you want to hire me to do it. My rates are pretty reasonable
 for simple stuff like this.
 
 -Stut

Problem solved:
function __autoload($c) {
  $m = array();
  preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
  if (count($m)) {
   require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
'.inc.php'));
  }
 }

However (perhaps a more appropriate question), do you think there is an
easier/better way to do this??

Alex

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com 
Version: 8.0.175 / Virus Database: 270.8.3/1748 - Release Date: 27/10/2008
07:57


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



Re: [PHP] preg_match

2008-10-27 Thread Stut

On 27 Oct 2008, at 15:46, Alex Chamberlain wrote:

Problem solved:
function __autoload($c) {
 $m = array();
 preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
 if (count($m)) {
  require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
'.inc.php'));
 }
}

However (perhaps a more appropriate question), do you think there is  
an

easier/better way to do this??


See, that wasn't so hard was it!!

Personally I'd have gone with something more like this...

function __autoload($class)
{
  if (substr($class, -10) == 'Controller')
  {
// No need for realpath here, it's not doing anything useful
// The _once is probably redundant too, but it may be required
// depending on how your code is arranged.
require FS_CONTROLLER.'/'.strtolower($class).'.inc.php';
  }
}

...but there's always more than one solution.

-Stut

--
http://stut.net/

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



Re: [PHP] preg_match

2008-10-27 Thread Eric Butera
On Mon, Oct 27, 2008 at 11:54 AM, Stut [EMAIL PROTECTED] wrote:
 On 27 Oct 2008, at 15:46, Alex Chamberlain wrote:

 Problem solved:
 function __autoload($c) {
  $m = array();
  preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
  if (count($m)) {
  require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
 '.inc.php'));
  }
 }

 However (perhaps a more appropriate question), do you think there is an
 easier/better way to do this??

 See, that wasn't so hard was it!!

 Personally I'd have gone with something more like this...

 function __autoload($class)
 {
  if (substr($class, -10) == 'Controller')
  {
// No need for realpath here, it's not doing anything useful
// The _once is probably redundant too, but it may be required
// depending on how your code is arranged.
require FS_CONTROLLER.'/'.strtolower($class).'.inc.php';
  }
 }

 ...but there's always more than one solution.

 -Stut

 --
 http://stut.net/

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



I'd just like to add spl autoload is friendlier since __autoload can
only be defined once.

http://us.php.net/manual/en/function.spl-autoload-register.php

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



Re: [PHP] preg_match

2008-10-27 Thread Stut

Please keep the conversation on the list!

On 27 Oct 2008, at 16:06, Alex Chamberlain wrote:

-Original Message-
From: Stut [mailto:[EMAIL PROTECTED]
Sent: 27 October 2008 15:54
To: Alex Chamberlain
Cc: 'PHP General list'
Subject: Re: [PHP] preg_match

On 27 Oct 2008, at 15:46, Alex Chamberlain wrote:

Problem solved:
function __autoload($c) {
$m = array();
preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
if (count($m)) {
 require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
'.inc.php'));
}
}

However (perhaps a more appropriate question), do you think there is
an
easier/better way to do this??


See, that wasn't so hard was it!!

Personally I'd have gone with something more like this...

function __autoload($class)
{
  if (substr($class, -10) == 'Controller')
  {
// No need for realpath here, it's not doing anything useful
// The _once is probably redundant too, but it may be required
// depending on how your code is arranged.
require FS_CONTROLLER.'/'.strtolower($class).'.inc.php';
  }
}

...but there's always more than one solution.

-Stut



Ok, spurred on with the success so far (but not changing the form of  
my code

just yet), I changed it to:

function __autoload($c) {
 $m = array();

 preg_match('/Fred(^[A-Z][a-zA-Z]+)/', $c, $m);
 if (count($m)) {
  require_once(realpath(FS_COMPONENT . '/' . strtolower($m[1]) .
'.inc.php'));
 }

 var_dump($m);

 preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
 if (count($m)) {
  require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
'.inc.php'));
 }
}

With the aim of also matching anything starting with 'Fred'. It  
didn't work

until I took the caret ^ out:

function __autoload($c) {
 $m = array();

 preg_match('/Fred([A-Z][a-zA-Z]+)/', $c, $m);
 if (count($m)) {
  require_once(realpath(FS_COMPONENT . '/' . strtolower($m[1]) .
'.inc.php'));
 }

 var_dump($m);

 preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
 if (count($m)) {
  require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
'.inc.php'));
 }
}

What I don't understand is why I needed it in one, but not in  
another??


If you're going to use regular expressions you need to read the manual  
to understand how they work. There's a whole section of the manual  
that covers this - go read it to understand what the ^ means!


-Stut

--
http://stut.net/

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



RE: [PHP] preg_match

2008-10-27 Thread Boyd, Todd M.
 -Original Message-
 From: Alex Chamberlain [mailto:[EMAIL PROTECTED]
 Sent: Monday, October 27, 2008 10:09 AM
 To: PHP General list
 Subject: [PHP] preg_match
 
 Hi,
 
 I don't understand regular expressions at all - I will make an effort
 to
 learn about them one day, but I need a solution today. I want to use
 the
 __autoload function, but not for all my class only those that finish
in
 'Controller'. So for instance,
 
 'ErrorController' should load 'errorcontroller.inc.php'
 'IndexController' should load 'indexcontroller.inc.php'
 'FooBar' should NOT load anything whatsoever.
 
 Can you help me write an __autoload function please??

http://www.regular-expressions.info

Awesome website. You should be a veritable RegEx guru after reading that
site for one day. (It'll also tell you what the ^ and $ means, as well
as that (?:) group).


Todd Boyd
Web Programmer

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



Re: [PHP] preg_match() returns false but no documentation why

2007-05-31 Thread Richard Lynch
On Wed, May 30, 2007 4:25 pm, Jared Farrish wrote:
 On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

 If you can't find them documented, print them out:

 echo PREG_NO_ERROR: ', PREG_NO_ERROR, ';


 Doh!

 PREG_NO_ERROR: 0
 PREG_INTERNAL_ERROR: 1
 PREG_BACKTRACK_LIMIT_ERROR: 2
 PREG_RECURSION_LIMIT_ERROR: 3
 PREG_BAD_UTF8_ERROR: 4

 So apparently, PREG_NO_ERROR is synonymous for you need delimiters,
 egghead.

I think the error mechanism you are checking never even had a chance
to kick in...

It's kind of like an in-flight warning system for an airplane that
never got off the ground...  It's going to keep saying no error
while the plane burns to a cinder if it never got turned on in the
first place as it never got in the air.

preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

 Try using | instead of / for your delimiter, so that you don't have
 to
 dink around with escaping the / in the pattern...


 You only have to escape / if  it's part if it's the pattern
 delimiter?

 Makes the code less cluttered and more clear.


 Fo' sho'.

Yup.

You only need to escape the delimiter you chose if it's in the pattern.

Or, looking at it from the pattern point of view:  Pick a delimiter
you are unlikely to ever need in the pattern, so you won't need to
escape it.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie 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() returns false but no documentation why

2007-05-31 Thread Richard Lynch
On Wed, May 30, 2007 5:04 pm, Jim Lucas wrote:
 btw: why is there a period in the second pattern?  Also, why are you
 allowing for uppercase letters
 when the RFC's don't allow them?

LDAP URL domain can't be ALL CAPS?!

Last I heard, domain names were case-insensitive in every other URL...

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie 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



[PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jared Farrish

Hi all,

Can anybody spot why this doesn't seem to be working right? The manual (
http://us2.php.net/preg_match) says it returns false on error, but
preg_last_error() returns 0, which I assume points to the PREG_NO_ERROR
error code.

code
preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)
/code

I also tried ereg(), and have searched and gone through the comments. Why
would a regex operation return false?

That may be ugly, since I've not done a lot of regex's yet. I have checked
and $this-server does insert a valid string. What I am trying to do is
validate ldap://com.com and ldaps://com.com and all valid variations of. Is
there something wrong with the regex, or am I pumping an invalid format into
preg_match()?

Incidentally, I stole the last piece (after ldaps://) off a regex for email
addresses (from SitePoint,
http://www.sitepoint.com/article/regular-expressions-php).

Thanks!

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:
 Hi all,

 Can anybody spot why this doesn't seem to be working right? The manual
 (
 http://us2.php.net/preg_match) says it returns false on error, but
 preg_last_error() returns 0, which I assume points to the
 PREG_NO_ERROR
 error code.

 code
 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...

 /code

 I also tried ereg(), and have searched and gone through the comments.
 Why
 would a regex operation return false?

It would return false if your string doesn't match the expression.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie 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() returns false but no documentation why

2007-05-30 Thread Jared Farrish

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:

 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...


Which ones? I've got the starter ^ and the closer $, so what else am I
missing?


would a regex operation return false?

It would return false if your string doesn't match the expression.



The manual claims it will return a 0 signaling 0 matches found. And then,
under Return Values, it's says very quickly:

*preg_match()* returns *FALSE* if an error occurred.

If it's not returning ANYTHING I'm assuming it's faulting, but the calling
the error function returns 0 (kind've ironic, really...).

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Stut

Jared Farrish wrote:

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:

 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...


Which ones? I've got the starter ^ and the closer $, so what else am I
missing?


You need delimiters around the regex, as stated in the documentation.

preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

Although you don't need to use slashes, you can use any character you 
want but you must escape it in if it appears in the regex.



would a regex operation return false?

It would return false if your string doesn't match the expression.



The manual claims it will return a 0 signaling 0 matches found. And then,
under Return Values, it's says very quickly:

*preg_match()* returns *FALSE* if an error occurred.

If it's not returning ANYTHING I'm assuming it's faulting, but the calling
the error function returns 0 (kind've ironic, really...).


It will return false on an error, such as not having matching delimiters 
aroung the regex.


The error function may retuyrn 0, but which of the following constants 
is defined as 0?


PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR

-Stut

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



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Richard Lynch


On Wed, May 30, 2007 3:06 pm, Jared Farrish wrote:
 On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:
 On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:
 
  preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

 You are missing the start/end delimiters is your first problem...

 Which ones? I've got the starter ^ and the closer $, so what else
 am I
 missing?

Whatever character you want to use:

|^ldap(s)?//[a-zA-Z0-9-]*\\.[a-zA-Z.]{2,5}$|
%^ldap(s)?//[a-zA-Z0-9-]*\\.[a-zA-Z.]{2,5}$%
#^ldap(s)?//[a-zA-Z0-9-]*\\.[a-zA-Z.]{2,5}$#


 would a regex operation return false?

 It would return false if your string doesn't match the expression.


 The manual claims it will return a 0 signaling 0 matches found. And
 then,
 under Return Values, it's says very quickly:

 *preg_match()* returns *FALSE* if an error occurred.

 If it's not returning ANYTHING I'm assuming it's faulting, but the
 calling
 the error function returns 0 (kind've ironic, really...).

Use === to distinguish FALSE from 0, which are not the same.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie 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() returns false but no documentation why

2007-05-30 Thread Jared Farrish

On 5/30/07, Stut [EMAIL PROTECTED] wrote:


You need delimiters around the regex, as stated in the documentation.

preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

Although you don't need to use slashes, you can use any character you
want but you must escape it in if it appears in the regex.



Oh! You know, I had looked over those a couple times already. Can't say why
I didn't see them.

It will return false on an error, such as not having matching delimiters

aroung the regex.

The error function may retuyrn 0, but which of the following constants
is defined as 0?

PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR



I don't know, I'm assuming it means no error... I couldn't see anywhere
where it mentioned what was what.

Now that I'm looking at it again, I see it's 5.2 or greater, and I think
we're on 5.1 or something. Although, it seems like it would have a fatal
error if I call a function that doesn't exist...


Use === to distinguish FALSE from 0, which are not the same.


I realize they're not the same. What I was saying was that false is not
the stated return value if it's not found. If it's not printing a zero,
shouldn't that mean it's returning false?

preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

Now when I add the slashes, I get zero, even though I give it a real value
that should return 1. *sigh*

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Richard Lynch
On Wed, May 30, 2007 3:25 pm, Jared Farrish wrote:
 On 5/30/07, Stut [EMAIL PROTECTED] wrote:

 You need delimiters around the regex, as stated in the
 documentation.

 preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

 Although you don't need to use slashes, you can use any character
 you
 want but you must escape it in if it appears in the regex.


 Oh! You know, I had looked over those a couple times already. Can't
 say why
 I didn't see them.

 It will return false on an error, such as not having matching
 delimiters
 aroung the regex.

 The error function may retuyrn 0, but which of the following
 constants
 is defined as 0?

 PREG_NO_ERROR
 PREG_INTERNAL_ERROR
 PREG_BACKTRACK_LIMIT_ERROR
 PREG_RECURSION_LIMIT_ERROR
 PREG_BAD_UTF8_ERROR


 I don't know, I'm assuming it means no error... I couldn't see
 anywhere
 where it mentioned what was what.

If you can't find them documented, print them out:

echo PREG_NO_ERROR: ', PREG_NO_ERROR, ';

Or even:
var_dump(PREG_NO_ERROR);

 Now that I'm looking at it again, I see it's 5.2 or greater, and I
 think
 we're on 5.1 or something. Although, it seems like it would have a
 fatal
 error if I call a function that doesn't exist...

The function exists.

The constants may not...

 Use === to distinguish FALSE from 0, which are not the same.

 I realize they're not the same. What I was saying was that false is
 not
 the stated return value if it's not found. If it's not printing a
 zero,
 shouldn't that mean it's returning false?

 preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

Try using | instead of / for your delimiter, so that you don't have to
dink around with escaping the / in the pattern...

Makes the code less cluttered and more clear.

Unless you have | in your pattern, or need the Regex branch '|'
character.

 Now when I add the slashes, I get zero, even though I give it a real
 value
 that should return 1. *sigh*

You may want \\. for the . in dot com

Download and play with The Regex Coach

It does pretty color syntax highlighting of the target string and your
regex to show you what's going on, as well as a slow-motion instant
replay to step through it piece by piece.

Doesn't always match PHP perfectly, as it's for Perl, but, man, that
tool alone has saved me a few hundred hours.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie 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() returns false but no documentation why

2007-05-30 Thread Jared Farrish

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:


If you can't find them documented, print them out:

echo PREG_NO_ERROR: ', PREG_NO_ERROR, ';



Doh!

PREG_NO_ERROR: 0
PREG_INTERNAL_ERROR: 1
PREG_BACKTRACK_LIMIT_ERROR: 2
PREG_RECURSION_LIMIT_ERROR: 3
PREG_BAD_UTF8_ERROR: 4

So apparently, PREG_NO_ERROR is synonymous for you need delimiters,
egghead.



preg_match(/^ldap(s)?:\/\/([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$/,$this-server)

Try using | instead of / for your delimiter, so that you don't have to
dink around with escaping the / in the pattern...



You only have to escape / if  it's part if it's the pattern delimiter?

Makes the code less cluttered and more clear.


Fo' sho'.



 Now when I add the slashes, I get zero, even though I give it a real
 value
 that should return 1. *sigh*

You may want \\. for the . in dot com



Ok, I tried:

preg_match(|^ldap(s)?://([a-zA-Z0-9-])+\.[a-zA-Z.]{2,5}$|,$this-server)
preg_match(|^ldap(s)?://([a-zA-Z0-9-])+\\.[a-zA-Z.]{2,5}$|,$this-server)
preg_match(|^ldap(s)?:\/\/([a-zA-Z0-9-])+\\.[a-zA-Z.]{2,5}$|,$this-server)

using: $this-server = ldap://www.example.com;;

No luck. I'll the try tool you referred to; I have been using
regular-expressions.info for information.

Download and play with The Regex Coach


It does pretty color syntax highlighting of the target string and your
regex to show you what's going on, as well as a slow-motion instant
replay to step through it piece by piece.



Oooh, pretty colors! Stepping through sounds interesting. I'll have to check
it out.

Thanks!

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: If the only tool you have is a hammer, you tend to see
every problem as a nail. $$


Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Jim Lucas

Stut wrote:

Jared Farrish wrote:

On 5/30/07, Richard Lynch [EMAIL PROTECTED] wrote:

On Wed, May 30, 2007 12:33 pm, Jared Farrish wrote:

 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)

You are missing the start/end delimiters is your first problem...


Which ones? I've got the starter ^ and the closer $, so what else 
am I

missing?


You need delimiters around the regex, as stated in the documentation.

preg_match(/^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/,$this-server)

This isn't going to work, the op has two forward slashes in the string that he 
is wanting to match with.

The op will need to use something other than forward slashes.

so, this is going to match:
ldap://testing123.com   TRUE
ldap://www.testing-123.com  FALSE
ldap://testing123.com.ukFALSE
ldap://testing123.or.us TRUE

preg_match('|^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$|', $this-server )

I also recommend using single quotes instead of double quotes here.

btw: why is there a period in the second pattern?  Also, why are you allowing for uppercase letters 
when the RFC's don't allow them?


Just my thoughts



Although you don't need to use slashes, you can use any character you 
want but you must escape it in if it appears in the regex.



would a regex operation return false?

It would return false if your string doesn't match the expression.



The manual claims it will return a 0 signaling 0 matches found. And 
then,

under Return Values, it's says very quickly:

*preg_match()* returns *FALSE* if an error occurred.

If it's not returning ANYTHING I'm assuming it's faulting, but the 
calling

the error function returns 0 (kind've ironic, really...).


It will return false on an error, such as not having matching delimiters 
aroung the regex.


The error function may retuyrn 0, but which of the following constants 
is defined as 0?


PREG_NO_ERROR
PREG_INTERNAL_ERROR
PREG_BACKTRACK_LIMIT_ERROR
PREG_RECURSION_LIMIT_ERROR
PREG_BAD_UTF8_ERROR

-Stut




--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Unknown

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



Re: [PHP] preg_match() returns false but no documentation why

2007-05-30 Thread Crayon Shin Chan
On Thursday 31 May 2007 01:33, Jared Farrish wrote:

 Can anybody spot why this doesn't seem to be working right? The manual
 ( http://us2.php.net/preg_match) says it returns false on error, but
 preg_last_error() returns 0, which I assume points to the
 PREG_NO_ERROR error code.

 code
 preg_match(^ldap(s)?://[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$,$this-server)
 /code

 I also tried ereg(), and have searched and gone through the comments.
 Why would a regex operation return false?

If you check your error log you'll find:

Warning: preg_match(): No ending delimiter '^' found in xxx.php on line xx

IMO that shouldn't be a warning, it should be an error that halts 
execution so people wouldn't go looking for a non-existant 
preg_last_error() when preg_match() did not even run.

-- 
Crayon

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



[PHP] preg_match

2007-02-06 Thread James Lockie
I am trying to use this code to display a button at the root but it 
always displays the button. :-(


   if (! (preg_match( /$\/index.php/, $_SERVER['PHP_SELF'] ))) {
# display a button


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



Re: [PHP] preg_match

2007-02-06 Thread Richard Lynch
On Tue, February 6, 2007 7:46 pm, James Lockie wrote:
 I am trying to use this code to display a button at the root but it
 always displays the button. :-(

 if (! (preg_match( /$\/index.php/, $_SERVER['PHP_SELF'] ))) {

Without any modifier, $ matches the END of the string.

It is impossible to have the end of the string followed by more stuff.

You maybe meant to add 'm' and or 's' after the ending '/', which
would indicate that you are looking for a newline followed by
'\/index.php' but I doubt that that is what you want either...

I don't think you want the $ in there at all...

Or maybe you want it right before the final '/' to make sure the URL
has nothing else after the 'index.php' part.

-- 
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

2007-02-06 Thread Myron Turner

James Lockie wrote:
I am trying to use this code to display a button at the root but it 
always displays the button. :-(


   if (! (preg_match( /$\/index.php/, $_SERVER['PHP_SELF'] ))) {
# display a button



You got the end-of-string character ($) in the wrong place:
if (! (preg_match( /\/index.php$/, $_SERVER['PHP_SELF'] ))) {


--

_
Myron Turner
http://www.room535.org
http://www.bstatzero.org
http://www.mturner.org/XML_PullParser/

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



Re: [PHP] preg_match

2007-02-06 Thread James Lockie

Myron Turner wrote:

James Lockie wrote:
I am trying to use this code to display a button at the root but it 
always displays the button. :-(


   if (! (preg_match( /$\/index.php/, $_SERVER['PHP_SELF'] ))) {
# display a button



You got the end-of-string character ($) in the wrong place:
if (! (preg_match( /\/index.php$/, $_SERVER['PHP_SELF'] ))) {



Richard Lynch wrote:

On Tue, February 6, 2007 7:46 pm, James Lockie wrote:
  

I am trying to use this code to display a button at the root but it
always displays the button. :-(

if (! (preg_match( /$\/index.php/, $_SERVER['PHP_SELF'] ))) {



Without any modifier, $ matches the END of the string.

I wanted this. :-(
Thanks.

if (! (preg_match( /^\/index.php/, $_SERVER['PHP_SELF'] ))) {
# display a button

--
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:

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



[PHP] preg_match to preg_replace

2006-12-11 Thread Peter Lauri
Hi guys,

I have a sample string [hp-ex][log]peter[hall o] that I need to process. I
need to remove the [] and separate the sections with a space. If there are
more then one [] part the first part should be bold (add b/b around it).
I have a solution that is working very well, but am thinking that I can do
this with preg_replace directly, what do you think? The final output is
always found in $thestr. Can all this be done with one preg_replace?

?php

echo pre;

$str = [hp-ex][log]peter[hall o];

preg_match_all(/\[(.+?)\]/, $str, $matches);

print_r($matches);

$m1 = $matches[0];
$m2 = $matches[1];

if(count($m1)1) {
$m2[0] = b$m2[0]/b;
$thestr = implode( , $m2);
} elseif(count($m1)==1) {
$thestr = $m2[0];
} else $thestr = ;

echo $thestr;

echo /pre;

?

Best regards,
Peter Lauri

www.dwsasia.com - company website
www.lauri.se - personal website

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



Re: [PHP] Preg_match - Find URL and convert to lower case

2006-12-01 Thread Richard Lynch
On Thu, November 30, 2006 5:04 pm, Kevin Murphy wrote:
 Well the problem would be then that the entire string would be lower
 case, and I only can have the link as lower case. Is there a way to
 apply strtolower into the preg_match?

Why not use lower(link) in SQL to get the link out in the first place?

Also, the domain part cannot be case-sensitive, so you needn't worry
about that part.

For the 10% that don't work, a quick check with common variants on
capitalization might help to fix those up.

-- 
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 - Find URL and convert to lower case

2006-12-01 Thread Kevin Murphy

On Dec 1, 2006, at 1:56 PM, Richard Lynch wrote:


On Thu, November 30, 2006 5:04 pm, Kevin Murphy wrote:

Well the problem would be then that the entire string would be lower
case, and I only can have the link as lower case. Is there a way to
apply strtolower into the preg_match?


Why not use lower(link) in SQL to get the link out in the first place?

Also, the domain part cannot be case-sensitive, so you needn't worry
about that part.

For the 10% that don't work, a quick check with common variants on
capitalization might help to fix those up.


Since these are mostly instructor's websites, that last 10% I figure  
it would be easier to just ask the instructors to change their site  
addresses.


Since these are in the middle of the text, I don't think that lower  
will work. Doesn't it just do the same thing as strtolower? The query  
as is right now is (edited) select note_text as note_text from  
classes  where note_text is many lines of text and in the middle of  
some are links and emails.


What I ended up with, is this, which takes care of website addresses  
and emails as well (although those stay all-caps). The str_replace is  
there because some have the HTTP and some don't and I figured it was  
easier to just wipe them all out first.


$section_notes = str_replace(HTTP://,,$section_notes);
$section_notes = preg_replace('/WWW.(.*?) /e', 'a href=\http:// 
www. . strtolower($1) . \ target=\_blank\http://www.; .  
strtolower($1) . /a', $section_notes);
$section_notes = eregi_replace((([a-z0-9_]|\\-|\\.)+@([^[:space:]]*) 
([[:alnum:]-])), a href=\mailto:\\1\;\\1/a,$section_notes);


Anyone have a better idea on how to accomplish the same thing?

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326

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



[PHP] Preg_match - Find URL and convert to lower case

2006-11-30 Thread Kevin Murphy
I have some text that comes out of a database all in uppercase (old  
IBM Mainframe that only supports uppercase characters).


Occasionally there are web addresses in this text and so I am trying  
to find them, convert them to a link, and convert them all to all  
lower case. Yes, I know that will not work for all links. However, it  
will work for about 90% of the links I have (vs. about 10% of them now).


So anyway, here is my first stab at this, but it only finds the link  
and converts the first part to lowercase and converts it to a link.  
Is there anyway to convert the output to all lowercase by doing  
something like this? Or is there a better way?


$pattern = /WWW.(.*?) /i;
$replace = a href=\http://www.\\1\;http://www.\\1/a;
$section_notes = preg_replace($pattern,$replace,$section_notes);

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326




Re: [PHP] Preg_match - Find URL and convert to lower case

2006-11-30 Thread Dave Goodchild

Why not use strtolower on the string after the replacements have been made?








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


Re: [PHP] Preg_match - Find URL and convert to lower case

2006-11-30 Thread Kevin Murphy
Well the problem would be then that the entire string would be lower  
case, and I only can have the link as lower case. Is there a way to  
apply strtolower into the preg_match?



--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Nov 30, 2006, at 2:26 PM, Dave Goodchild wrote:

Why not use strtolower on the string after the replacements have  
been made?









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




[PHP] Re: SOLVED: [PHP] Preg_match - Find URL and convert to lower case

2006-11-30 Thread Kevin Murphy
$section_notes = preg_replace('/WWW.(.*?) /e', 'a href=\http:// 
www. . strtolower($1) . \ target=\_blank\http://www.; .  
strtolower($1) . /a', $section_notes);


For some reason I can't get it to work if I decare those items as  
variables. They have to be inside the preg_replace as written. But,  
it works now. Thanks for the help.


--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Nov 30, 2006, at 3:04 PM, Kevin Murphy wrote:

Well the problem would be then that the entire string would be  
lower case, and I only can have the link as lower case. Is there a  
way to apply strtolower into the preg_match?



--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada Community College
www.wncc.edu
775-445-3326


On Nov 30, 2006, at 2:26 PM, Dave Goodchild wrote:

Why not use strtolower on the string after the replacements have  
been made?









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






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



  1   2   3   >