Re: [PHP] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-21 00:11:13 +0100: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 16:59:26 +0100: wouldn't it be fair to assume (safety through paranoia) that ctype_alnum() would suffer the same problem? (given the manual's indication that ctype_alnum() and the offending regexp are equivalent?) isalnum(3) uses isalpha(3) and isdigit(3), so yes, their results are locale-dependent (LC_CTYPE, see setlocale(3)), but don't depend on collating sequence. so really the doc's are slightly misleading or even incorrect, Slightly, in a usually-behaves-as-described-but-for-different-reasons way. as a side note: do you have any real world example of where this collation issue might actually bite someone making use of the aforementioned regexp range? Not off the top of my head. :( -- 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] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-21 10:48:30 +: # [EMAIL PROTECTED] / 2007-01-21 00:11:13 +0100: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 16:59:26 +0100: wouldn't it be fair to assume (safety through paranoia) that ctype_alnum() would suffer the same problem? (given the manual's indication that ctype_alnum() and the offending regexp are equivalent?) isalnum(3) uses isalpha(3) and isdigit(3), so yes, their results are locale-dependent (LC_CTYPE, see setlocale(3)), but don't depend on collating sequence. so really the doc's are slightly misleading or even incorrect, Slightly, in a usually-behaves-as-described-but-for-different-reasons way. as a side note: do you have any real world example of where this collation issue might actually bite someone making use of the aforementioned regexp range? Not off the top of my head. :( Trying the Czech locale (I normally run with the values below), I've come across some unexpected behavior. 0xE8 is c caron, and sorts between c and d, but not on this computer. 0xBE is z caron, and sorts just after z. I'd expect [a-z] to match 0xE8 but it does not. LANG=cs_CZ.ISO8859-2 LC_COLLATE=en_US.ISO8859-1 LC_CTYPE=en_US.ISO8859-1 LC_MESSAGES=en_US.ISO8859-1 LC_NUMERIC=en_US.ISO8859-1 LC_TIME=en_US.ISO8859-1 [EMAIL PROTECTED] ~/tmp/blemc 1042:0 uname -srm FreeBSD 6.1-PRERELEASE amd64 [EMAIL PROTECTED] ~/tmp/blemc 1043:0 cat ./collseq.php #!/usr/bin/env php ?php function f($c, $l) { printf(char=%c locale=%s\n, $c, $l); setlocale(LC_COLLATE, $l); setlocale(LC_CTYPE, $l); printf([a-z] = %s\n, var_export(preg_match('~[a-z]~', chr($c)), 1)); printf([[:lower:]] = %s\n, var_export(preg_match('~[[:lower:]]~', chr($c)), 1)); printf(islower(3) = %s\n, var_export(ctype_lower(chr($c)), 1)); print \n; } f(0xE8, 'C'); f(0xE8, 'cs_CZ.ISO8859-2'); f(0xBE, 'C'); f(0xBE, 'cs_CZ.ISO8859-2'); [EMAIL PROTECTED] ~/tmp/blemc 1044:0 ./collseq.php char=č locale=C [a-z] = 0 [[:lower:]] = 0 islower(3) = false char=č locale=cs_CZ.ISO8859-2 [a-z] = 0 [[:lower:]] = 1 islower(3) = true char=ž locale=C [a-z] = 0 [[:lower:]] = 0 islower(3) = false char=ž locale=cs_CZ.ISO8859-2 [a-z] = 0 [[:lower:]] = 1 islower(3) = true -- 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] I lied, another question / problem
Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 16:59:26 +0100: Roman Neuhauser wrote: re_format(7) on FreeBSD: A bracket expression is a list of characters enclosed in `[]'. (...) If two characters in the list are separated by `-', this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. (...) Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them. one other thing ... wouldn't it be fair to assume (safety through paranoia) that ctype_alnum() would suffer the same problem? (given the manual's indication that ctype_alnum() and the offending regexp are equivalent?) isalnum(3) uses isalpha(3) and isdigit(3), so yes, their results are locale-dependent (LC_CTYPE, see setlocale(3)), but don't depend on collating sequence. so really the doc's are slightly misleading or even incorrect, I will try to formulate a succinct question for internals@ to ask whether this should be reported as documentation bug. as a side note: do you have any real world example of where this collation issue might actually bite someone making use of the aforementioned regexp range? isdigit(3): The isdigit() function tests for a decimal digit character. Regardless of locale, this includes the following characters only: ``0'' ``1'' ``2'' ``3'' ``4'' ``5'' ``6'' ``7'' ``8'' ``9'' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-17 01:42:09 +0100: Beauford wrote: Further to my previous email, there is something weird going on here. I just tried using this: if (!ereg('^[A-Za-z0-9]', $strvalue)) { return error; } stop using bleeding ereg*() function - move to preg_*() funcs like the rest of the world did 5+ years ago. Or even better: how about using the right tool for the job? :) if (!ctype_isalnum($strvalue)) { return error; } if (!preg_match(#^[A-Z0-9]+\$#i, $s)) { (ps the above is a crappy regexp for real world use imho, but it serves the purpose of example) It's dangerous. -- 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] I lied, another question / problem
Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 01:42:09 +0100: Beauford wrote: Further to my previous email, there is something weird going on here. I just tried using this: if (!ereg('^[A-Za-z0-9]', $strvalue)) { return error; } stop using bleeding ereg*() function - move to preg_*() funcs like the rest of the world did 5+ years ago. Or even better: how about using the right tool for the job? :) true, although the function should be spelled correct to avoid fatal errors ;-) if (!ctype_isalnum($strvalue)) { return error; } if (!preg_match(#^[A-Z0-9]+\$#i, $s)) { (ps the above is a crappy regexp for real world use imho, but it serves the purpose of example) It's dangerous. why dangerous? given that this page: http://php.net/manual/en/function.ctype-alnum.php says, and I quote: Checks if all of the characters in the provided string, text, are alphanumeric. In the standard C locale letters are just [A-Za-z] and the function is equivalent to preg_match('/^[a-z0-9]+$/iD', $text). the 'D' modifier being the only difference in my example regexp and the equilavent given on the ctype_alnum() page ... I grant that the 'D' modifier might the difference between dangerous and not dangerous, if that's the case please explain (because I'm not seeing it :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-17 11:41:54 +0100: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 01:42:09 +0100: if (!preg_match(#^[A-Z0-9]+\$#i, $s)) { (ps the above is a crappy regexp for real world use imho, but it serves the purpose of example) It's dangerous. why dangerous? given that this page: http://php.net/manual/en/function.ctype-alnum.php says, and I quote: Checks if all of the characters in the provided string, text, are alphanumeric. In the standard C locale letters are just [A-Za-z] and the function is equivalent to preg_match('/^[a-z0-9]+$/iD', $text). re_format(7) on FreeBSD: A bracket expression is a list of characters enclosed in `[]'. (...) If two characters in the list are separated by `-', this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. (...) Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them. -- 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] I lied, another question / problem
Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 11:41:54 +0100: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 01:42:09 +0100: if (!preg_match(#^[A-Z0-9]+\$#i, $s)) { (ps the above is a crappy regexp for real world use imho, but it serves the purpose of example) It's dangerous. why dangerous? given that this page: http://php.net/manual/en/function.ctype-alnum.php says, and I quote: Checks if all of the characters in the provided string, text, are alphanumeric. In the standard C locale letters are just [A-Za-z] and the function is equivalent to preg_match('/^[a-z0-9]+$/iD', $text). re_format(7) on FreeBSD: A bracket expression is a list of characters enclosed in `[]'. (...) If two characters in the list are separated by `-', this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. (...) Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them. ah, thanks for that. what would you suggest instead of 'a-z' in this instance, *if* the OP wants *just* the chars [in ASCII] from a to Z then the only thing I could think of would be to use a string of 26 chars ... is there a better way? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 11:41:54 +0100: Roman Neuhauser wrote: # [EMAIL PROTECTED] / 2007-01-17 01:42:09 +0100: if (!preg_match(#^[A-Z0-9]+\$#i, $s)) { (ps the above is a crappy regexp for real world use imho, but it serves the purpose of example) It's dangerous. why dangerous? given that this page: http://php.net/manual/en/function.ctype-alnum.php says, and I quote: Checks if all of the characters in the provided string, text, are alphanumeric. In the standard C locale letters are just [A-Za-z] and the function is equivalent to preg_match('/^[a-z0-9]+$/iD', $text). re_format(7) on FreeBSD: A bracket expression is a list of characters enclosed in `[]'. (...) If two characters in the list are separated by `-', this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. (...) Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them. one other thing ... wouldn't it be fair to assume (safety through paranoia) that ctype_alnum() would suffer the same problem? (given the manual's indication that ctype_alnum() and the offending regexp are equivalent?) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-17 16:59:26 +0100: Roman Neuhauser wrote: re_format(7) on FreeBSD: A bracket expression is a list of characters enclosed in `[]'. (...) If two characters in the list are separated by `-', this is shorthand for the full range of characters between those two (inclusive) in the collating sequence, e.g. `[0-9]' in ASCII matches any decimal digit. (...) Ranges are very collating-sequence-dependent, and portable programs should avoid relying on them. one other thing ... wouldn't it be fair to assume (safety through paranoia) that ctype_alnum() would suffer the same problem? (given the manual's indication that ctype_alnum() and the offending regexp are equivalent?) isalnum(3) uses isalpha(3) and isdigit(3), so yes, their results are locale-dependent (LC_CTYPE, see setlocale(3)), but don't depend on collating sequence. isdigit(3): The isdigit() function tests for a decimal digit character. Regardless of locale, this includes the following characters only: ``0'' ``1'' ``2'' ``3'' ``4'' ``5'' ``6'' ``7'' ``8'' ``9'' -- 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] I lied, another question / problem
I believe that only two things could be messing up your validation: a) input data b) your function a) Do a var_dump on your input data. Is there any white space characters or anything else that do not belong there in the string? b) Rewrite your function/rethink what you are doing. You said that your function should match letters from a to Z and some special characters like ' - _ . Try this regex: ^(\w+\s?[\'\-\_\.]?)+$ I would write the function as follows: function invalidchar ( $input ) { if ( preg_match ( ^(\w+\s?[\'\-\_\.]?)+$, $input ) ) { // string matches against the pattern, everything is ok return $input; } else { return false; } } if ( invalidchar ( $my_string ) == false ) { // do some stuff } else { echo You passed the test; } // untested // frank 16 jan 2007 kl. 04.47 skrev Beauford: My apologies, but I am just so frustrated right now. It seems my function doesn't work either (if that's even the problem, which at this time I just don't know). Somehow my variable is still getting a value, and I have no idea how. Even if I don't return anything it still gets a value. Basically this has just broken my whole site. If anyone can figure this out let me know, right now I just have to put this site up with no validation. Thanks -Original Message- From: Beauford Sent: January 15, 2007 10:26 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problem Does anyone have any idea to this problem? All the code is in the emails I have written to the list. I have temporarily solved the problem by writing my own function not using any pregs, eregs, or any other regs and it works perfectly. It's probably not considered good programming, but it works the way it is supposed to. I would however like to know what the issue is with the original code, or if this is actually a bug in PHP. Thanks -Original Message- From: Beauford [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:22 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problem -Original Message- From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:53 PM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. I'm still confused. This works perfectly on my other two pages with the exact same code. So why is it only this one page that is causing a problem? I don't know, I don't care. You have enough problems with the single regex, let's concentrate on fixing this first. This certainly has a bearing. If the code works here then there is nothing wrong with the code. There is something else going on. If I enter the word test in my form, without the quotes, then why is the fuction returning anything since this is a valid entry. Should it not only return a value if there is a problem. I don't understand that paragraph. The regexp matches, and the function returns *nothing* just as you programmed it. That, of course, means that the variable you are assigning this *nothing* gets set to *nothing*, which, in PHP lingo, is null. The problem is that it is returning *something*, and that's what I am trying to figure out. If I put this in my code after I do the checking it works, but it should not work if the function is retuning *nothing*. So the original question remains, what is being returned and why? If($formerror) echo Testing; This will display Testing - it should not display anything since nothing should be returned. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. Thanks -- 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] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-15 19:22:24 -0500: From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? That's a value the regexp will match. Is that intended? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. You don't understand that single function, and it does something else than you think it does. I told you what it actually does, but you chose to ignore the information. I don't know how I could help you more. -- 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] I lied, another question / problem
Obviously I'm not quite understanding, maybe a further explanation is needed to help me understand. This is how I see it from what you said - am in in the right ballpark. The function is returning a null value if there is no error, and I guess PHP sees 'null' or as a value. So how do I get around this? This is how I call the function. if($result = ValidateString($orgname, 1)) { $formerror['orgname'] = $result; } If there is an error an error string will be returned (i.e. Error in field), if not I want nothing returned. Later on in the page I use - if(!$formerror) blah blah. This is where the problem is because if null or is being returned then $formerror has a value which breaks the above if. I hope this helps. Thanks -Original Message- From: Roman Neuhauser [mailto:[EMAIL PROTECTED] Sent: January 16, 2007 5:49 AM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 19:22:24 -0500: From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? That's a value the regexp will match. Is that intended? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. You don't understand that single function, and it does something else than you think it does. I told you what it actually does, but you chose to ignore the information. I don't know how I could help you more. -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
Beauford wrote: Obviously I'm not quite understanding, maybe a further explanation is needed to help me understand. This is how I see it from what you said - am in in the right ballpark. The function is returning a null value if there is no error, and I guess PHP sees 'null' or as a value. So how do I get around this? This is how I call the function. if($result = ValidateString($orgname, 1)) { $formerror['orgname'] = $result; } If there is an error an error string will be returned (i.e. Error in field), if not I want nothing returned. Later on in the page I use - if(!$formerror) blah blah. This is a bad way to test for a value also, unless you expecting only TRUE or FALSE and you are sure that it will always be set. Otherwise you should do something like this if ( isset($formerror) $formerror != '' ) { // Display Error } Also, going back to your original post, the function function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { return *; } } You would always return SOMETHING. Even if it is FALSE Give this a try: ?PHP function invalidchar($strvalue) { if ( preg_match(|^[[:alpha:][:space:]\'\.-]+$|, $strvalue) ) { return $strvalue; } return 'BAD'; //-- For testing only return FALSE; //-- Left this so you could return false and not a string } echo '('.invalidchar('something').')'; ? Jim Lucas This is where the problem is because if null or is being returned then $formerror has a value which breaks the above if. I hope this helps. Thanks -Original Message- From: Roman Neuhauser [mailto:[EMAIL PROTECTED] Sent: January 16, 2007 5:49 AM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 19:22:24 -0500: From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? That's a value the regexp will match. Is that intended? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. You don't understand that single function, and it does something else than you think it does. I told you what it actually does, but you chose to ignore the information. I don't know how I could help you more. -- 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I lied, another question / problem
This is a bad way to test for a value also, unless you expecting only TRUE or FALSE and you are sure that it will always be set. Otherwise you should do something like this if ( isset($formerror) $formerror != '' ) { // Display Error } The problem here is this. formerror is an array and can have formerror['a'], formerror['b'], etc. I don't care how many errors there are, I only want to know if there was an error somewhere along the way. Example: if I have two fields, Name and Age and they both have errors, I would echo $formerror['name'] and $formerror['age'] Then I check if(!$formerror) { do something.. This would not get done as the above two have errors, which is what I want. The problem still lies with something being returned from the function even if there are no errors. So if(!$formerror) never gets done. Which is the problem. Another question, and not related, how do I kill a session when someone leaves a particular page. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
Beauford wrote: ... function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. .. Further to my previous email, there is something weird going on here. I just tried using this: if (!ereg('^[A-Za-z0-9]', $strvalue)) { return error; } stop using bleeding ereg*() function - move to preg_*() funcs like the rest of the world did 5+ years ago. When I enter the word Test, which is valid, I am still getting an error 'Test' is not valid according to the regexp your using. ?php $strs = array(Test, Jochem, @##^%, , Test1, Test!, J*nk); // match a non-empty string containing *only* alpha numeric chars foreach ($strs as $s) { if (!preg_match(#^[A-Z0-9]+\$#i, $s)) { echo error in string: \$s\ \n; } else { echo no problemo: \$s\ \n; } } ? (ps the above is a crappy regexp for real world use imho, but it serves the purpose of example) you need to read up and do lots of practicing with regexps - we do realise that regexps are not easy, unfortunately there is no shortcut to learning how to use them. I doubt many on this list could be considered expert in the field of regexps, but you have to get yourself a basic grasp or these things will bite you in the ass until the cows come home. start here: http://php.net/pcre http://php.net/manual/en/reference.pcre.pattern.modifiers.php http://php.net/manual/en/reference.pcre.pattern.syntax.php returned - but only on this one page. So there has got to be something on this page that is screwing this up, but what. I have been over and over this and can't see a problem. I could really use another pair of eyes on this as it is driving me nuts. I regexps drives everyone nuts to start with. first there is only the mountain, then the mountain is not a mountain, finally there is just mountain. am now into hour 6 with this. Absolutely ridiculous. thats nothing. most people take months to get anywhere useful with regexps, well okay I'm speaking for myself - I was in your position somewhere back in 2001, I was regularly sweating it for weeks trying to understand and getting certain regexps work 'properly'. don't give up. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
Beauford wrote: This is a bad way to test for a value also, unless you expecting only TRUE or FALSE and you are sure that it will always be set. Otherwise you should do something like this if ( isset($formerror) $formerror != '' ) { // Display Error } The problem here is this. formerror is an array Then check it as an array. $formerror = array(); ... do your validation here which may/may not add to the array. if (!empty($formerror)) { echo Something went wrong!; print_r($formerror); } else { echo Everything is ok!; } -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I lied, another question / problem
$formerror = array(); ... do your validation here which may/may not add to the array. if (!empty($formerror)) { echo Something went wrong!; print_r($formerror); } else { echo Everything is ok!; } As I said the problem is that a value is being returned, how I check it is really not an issue as I know there is value there. I guess I need to figure out how to only return something if there is an error, and not return anything if there is no error, or just totally revise the way I am doing this period. I have corrected the problem, but it is messy and it is cumbersome, but it will have to do until I can work out something better. At least now I can take my time and work on this. I appreciate all the suggestions and maybe I can incorporate some of them once I do a rewrite. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. -- 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] I lied, another question / problem
-Original Message- From: Roman Neuhauser [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:09 PM To: Beauford Cc: PHP Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. I'm still confused. This works perfectly on my other two pages with the exact same code. So why is it only this one page that is causing a problem? If I enter the word test in my form, without the quotes, then why is the fuction returning anything since this is a valid entry. Should it not only return a value if there is a problem. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] I lied, another question / problem
# [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. I'm still confused. This works perfectly on my other two pages with the exact same code. So why is it only this one page that is causing a problem? I don't know, I don't care. You have enough problems with the single regex, let's concentrate on fixing this first. If I enter the word test in my form, without the quotes, then why is the fuction returning anything since this is a valid entry. Should it not only return a value if there is a problem. I don't understand that paragraph. The regexp matches, and the function returns *nothing* just as you programmed it. That, of course, means that the variable you are assigning this *nothing* gets set to *nothing*, which, in PHP lingo, is null. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? -- 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] I lied, another question / problem
-Original Message- From: Roman Neuhauser [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:09 PM To: Beauford Cc: PHP Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. -- 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 Further to my previous email, there is something weird going on here. I just tried using this: if (!ereg('^[A-Za-z0-9]', $strvalue)) { return error; } When I enter the word Test, which is valid, I am still getting an error returned - but only on this one page. So there has got to be something on this page that is screwing this up, but what. I have been over and over this and can't see a problem. I could really use another pair of eyes on this as it is driving me nuts. I am now into hour 6 with this. Absolutely ridiculous. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I lied, another question / problem
-Original Message- From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:53 PM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. I'm still confused. This works perfectly on my other two pages with the exact same code. So why is it only this one page that is causing a problem? I don't know, I don't care. You have enough problems with the single regex, let's concentrate on fixing this first. This certainly has a bearing. If the code works here then there is nothing wrong with the code. There is something else going on. If I enter the word test in my form, without the quotes, then why is the fuction returning anything since this is a valid entry. Should it not only return a value if there is a problem. I don't understand that paragraph. The regexp matches, and the function returns *nothing* just as you programmed it. That, of course, means that the variable you are assigning this *nothing* gets set to *nothing*, which, in PHP lingo, is null. The problem is that it is returning *something*, and that's what I am trying to figure out. If I put this in my code after I do the checking it works, but it should not work if the function is retuning *nothing*. So the original question remains, what is being returned and why? If($formerror) echo Testing; This will display Testing - it should not display anything since nothing should be returned. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] I lied, another question / problem
Does anyone have any idea to this problem? All the code is in the emails I have written to the list. I have temporarily solved the problem by writing my own function not using any pregs, eregs, or any other regs and it works perfectly. It's probably not considered good programming, but it works the way it is supposed to. I would however like to know what the issue is with the original code, or if this is actually a bug in PHP. Thanks -Original Message- From: Beauford [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:22 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problem -Original Message- From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:53 PM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. I'm still confused. This works perfectly on my other two pages with the exact same code. So why is it only this one page that is causing a problem? I don't know, I don't care. You have enough problems with the single regex, let's concentrate on fixing this first. This certainly has a bearing. If the code works here then there is nothing wrong with the code. There is something else going on. If I enter the word test in my form, without the quotes, then why is the fuction returning anything since this is a valid entry. Should it not only return a value if there is a problem. I don't understand that paragraph. The regexp matches, and the function returns *nothing* just as you programmed it. That, of course, means that the variable you are assigning this *nothing* gets set to *nothing*, which, in PHP lingo, is null. The problem is that it is returning *something*, and that's what I am trying to figure out. If I put this in my code after I do the checking it works, but it should not work if the function is retuning *nothing*. So the original question remains, what is being returned and why? If($formerror) echo Testing; This will display Testing - it should not display anything since nothing should be returned. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. Thanks -- 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] I lied, another question / problem
My apologies, but I am just so frustrated right now. It seems my function doesn't work either (if that's even the problem, which at this time I just don't know). Somehow my variable is still getting a value, and I have no idea how. Even if I don't return anything it still gets a value. Basically this has just broken my whole site. If anyone can figure this out let me know, right now I just have to put this site up with no validation. Thanks -Original Message- From: Beauford Sent: January 15, 2007 10:26 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problem Does anyone have any idea to this problem? All the code is in the emails I have written to the list. I have temporarily solved the problem by writing my own function not using any pregs, eregs, or any other regs and it works perfectly. It's probably not considered good programming, but it works the way it is supposed to. I would however like to know what the issue is with the original code, or if this is actually a bug in PHP. Thanks -Original Message- From: Beauford [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:22 PM To: 'PHP' Subject: RE: [PHP] I lied, another question / problem -Original Message- From: 'Roman Neuhauser' [mailto:[EMAIL PROTECTED] Sent: January 15, 2007 7:53 PM To: Beauford Cc: 'PHP' Subject: Re: [PHP] I lied, another question / problem # [EMAIL PROTECTED] / 2007-01-15 18:33:31 -0500: From: Roman Neuhauser [mailto:[EMAIL PROTECTED] # [EMAIL PROTECTED] / 2007-01-15 16:31:32 -0500: I have file which I use for validating which includes the following function: function invalidchar($strvalue) { if(!ereg(^[[:alpha:][:space:]\'-.]*$, $strvalue)) { That regexp matches if $strvalue consists of zero or more ocurrences of a letter, a whitespace character, and any character whose numeric value lies between the numeric values of ' and . in your locale. Zero or more means it also matches an empty string. I'm still confused. This works perfectly on my other two pages with the exact same code. So why is it only this one page that is causing a problem? I don't know, I don't care. You have enough problems with the single regex, let's concentrate on fixing this first. This certainly has a bearing. If the code works here then there is nothing wrong with the code. There is something else going on. If I enter the word test in my form, without the quotes, then why is the fuction returning anything since this is a valid entry. Should it not only return a value if there is a problem. I don't understand that paragraph. The regexp matches, and the function returns *nothing* just as you programmed it. That, of course, means that the variable you are assigning this *nothing* gets set to *nothing*, which, in PHP lingo, is null. The problem is that it is returning *something*, and that's what I am trying to figure out. If I put this in my code after I do the checking it works, but it should not work if the function is retuning *nothing*. So the original question remains, what is being returned and why? If($formerror) echo Testing; This will display Testing - it should not display anything since nothing should be returned. All I want to accomplish here is to allow the user to enter a to z, A to Z, and /\'-_. and a space. Is there a better way to do this? 1. Do you really want to let them enter backslashes, or are you trying to escape the apostrophe? 2. Does that mean that /\'-_. (without the quotes) and (that's three spaces) are valid entries? Where do you see 3 spaces? In any event, I don't think this is the problem. As I have said the code works fine on two other pages, which logically suggests that there is something on this page that is causing a problem. Thanks -- 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