Re: [PHP] Preg Match Problem
On Wed, 2 Jun 2010 12:14:47 -0400 Alice Wei aj...@alumni.iu.edu wrote: Hi, I have a code snippet here as in the following: [CODE] $keywords = preg_split(/[\s,]+/, $day); $count = count($keywords); if(preg_match((Mon|Tue|Wed|Thu|Fri)/i, $keywords[$i])) { //line 40 $day_query =start_time.day='12345' AND end_time.day='12345'; } if(preg_match(Sat/i, $keywords[$i])) { //line 43 $day_query = start_time.Sat_route != 'NULL' AND end_time.Sat_route != 'NULL'; } else { echo $keywords[i] . is not a term that exists in the database. Make sure the pattern looks like bMon, Tue/bbr /; footer(); exit; } [/CODE] For some reason, when I type in Mon, Tue It gives me this: Warning: preg_match() [function.preg-match]: Unknown modifier '/' in line 40 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash on line 43 is not a term that exists in the database. Make sure the pattern looks like Mon, Tue You need a leading slash as a delimiter, eg /Sat/i also note that you will match any phrase that contains 'sun', 'mon' etc, which can also have irrelevant text, eg 'Mars Jupiter Saturn' will match, but thats probably not what you want -- Simcha Younger sim...@syounger.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preg Match Problem
Hi, I have a code snippet here as in the following: [CODE] $keywords = preg_split(/[\s,]+/, $day); $count = count($keywords); if(preg_match((Mon|Tue|Wed|Thu|Fri)/i, $keywords[$i])) { //line 40 $day_query =start_time.day='12345' AND end_time.day='12345'; } if(preg_match(Sat/i, $keywords[$i])) { //line 43 $day_query = start_time.Sat_route != 'NULL' AND end_time.Sat_route != 'NULL'; } else { echo $keywords[i] . is not a term that exists in the database. Make sure the pattern looks like bMon, Tue/bbr /; footer(); exit; } [/CODE] For some reason, when I type in Mon, Tue It gives me this: Warning: preg_match() [function.preg-match]: Unknown modifier '/' in line 40 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash on line 43 is not a term that exists in the database. Make sure the pattern looks like Mon, Tue Have I done something wrong here? Thanks for your help. _ Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2
Re: [PHP] Preg Match Problem
On 2 June 2010 18:14, Alice Wei aj...@alumni.iu.edu wrote: Hi, I have a code snippet here as in the following: [CODE] $keywords = preg_split(/[\s,]+/, $day); $count = count($keywords); if(preg_match((Mon|Tue|Wed|Thu|Fri)/i, $keywords[$i])) { //line 40 You're lacking the starting delimiter '/' Regards Peter -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Preg Match Problem
From: peter.e.l...@gmail.com Date: Wed, 2 Jun 2010 18:17:00 +0200 Subject: Re: [PHP] Preg Match Problem To: aj...@alumni.iu.edu CC: php-general@lists.php.net On 2 June 2010 18:14, Alice Wei aj...@alumni.iu.edu wrote: Hi, I have a code snippet here as in the following: [CODE] $keywords = preg_split(/[\s,]+/, $day); $count = count($keywords); if(preg_match((Mon|Tue|Wed|Thu|Fri)/i, $keywords[$i])) { //line 40 You're lacking the starting delimiter '/' Regards Peter Thanks, that did the trick. Alice -- hype WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 /hype _ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccountocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4
[PHP] preg match
This php script perform matching text of some certain URLs. but in this preg_match it wont match few patterns _ . with help of this script , can some body help me to match the other all patterns .plz ? ?php $user=root; $pass=; $db=aa; $dblink = mysql_connect(localhost:3306, $user, $pass)or die(Could not connect to db); mysql_select_db($db) or die (can't select the db); $result = mysql_query (select indexNo,Reply from Acknowledgement order by indexNo) or die (Invalid query); while ( $rset= mysql_fetch_array($result)) { /* Lets check the reply with the database*/ $chk_msg= $rset[Reply]; //echo checking $chk_msg in $msgbr; if ( preg_match(/$chk_msg/, $msg, $match) ) { // match found $SQL=update Status set Status = 'UP' where ServiceNo=.$rset[ServiceNo]; mysql_query ($SQL) or die (Invalid 2nd query); }else{ // SERIVCE DOWN // nothing to do here. //echo No match..br; } } mysql_close($dblink); ? thanx in advance, chandana
Re: [PHP] preg match
I'm not sure what you're trying to do with preg_match, since the parameters you send to it, are from the database, and an undeclared variable $msg(which is what exactly). Unless you give us examples of the arguments to preg_match, and what you expect the results should be, as well as what they are, we can't really be of much help. Having that said: You are using /$chk_msg/ as the first parameter. since you are simply putting /'s around $chk_msg, this leads me to suggest that you don't need regex at all, and perhaps would be better using some of the string functions. strpos() ( http://www.php.net/strpos ) springs to mind. Just a few tips: As an aside, I notice that you are connecting to localhost:3306. Just incase you didn't know, when you connect to localhost through mysql_connect, assuming you are on a unix host, it uses a unix socket, regardless if you specify a port. If you want to override this behavour, and use TCP sockets, you can connect to 127.0.0.1. On Sat, 8 Jan 2005 00:37:34 +0600, Chandana Bandara [EMAIL PROTECTED] wrote: This php script perform matching text of some certain URLs. but in this preg_match it wont match few patterns _ . with help of this script , can some body help me to match the other all patterns .plz ? ?php $user=root; $pass=; $db=aa; $dblink = mysql_connect(localhost:3306, $user, $pass)or die(Could not connect to db); mysql_select_db($db) or die (can't select the db); $result = mysql_query (select indexNo,Reply from Acknowledgement order by indexNo) or die (Invalid query); while ( $rset= mysql_fetch_array($result)) { /* Lets check the reply with the database*/ $chk_msg= $rset[Reply]; //echo checking $chk_msg in $msgbr; if ( preg_match(/$chk_msg/, $msg, $match) ) { // match found $SQL=update Status set Status = 'UP' where ServiceNo=.$rset[ServiceNo]; mysql_query ($SQL) or die (Invalid 2nd query); }else{ // SERIVCE DOWN // nothing to do here. //echo No match..br; } } mysql_close($dblink); ? thanx in advance, chandana -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg match compilation error
I found a reqular expresion that I'm using to check for valid characters in file names. Here's the sample code: if(preg_match([^a-zA-Z0-9,._\+\()\-],$filename)) { //blah, blah, blah } However, when I run the script I get the following error: Warning: Compilation failed: unmatched parentheses at offset 17 in /home/httpd/sigmarapid/html/test/upload.php on line 137 (the line with the preg_match) I'm new to regular expressions so any help would be greatly appreciated. Luis R. Lebron Sigmatech, Inc
Re: [PHP] preg match compilation error
* Thus wrote Luis Lebron ([EMAIL PROTECTED]): I found a reqular expresion that I'm using to check for valid characters in file names. Here's the sample code: if(preg_match([^a-zA-Z0-9,._\+\()\-],$filename)) { //blah, blah, blah } preg_* need a pattern deliminater (most commonly /,#, or !) so it should be: preg_match(/[^a-zA-Z0-9,._\+\()\-]/,$filename) Now you can get rid of all the escapes because mosts characters loose their special meaning inside a character class: preg_match(/[^a-zA-Z0-9,._+()-]/,$filename) You can get away without escaping the '-' because it *can't* be considered a range of characters since it is last (or if its first). That should work. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg match compilation error
Do you realy want to use [ and ] as patern delimiters? My quess is that you want to use it for defining character class. Then the only character that must be escaped is - '/[^a-z0-9,._+()\-]/i' Luis Lebron wrote: I found a reqular expresion that I'm using to check for valid characters in file names. Here's the sample code: if(preg_match([^a-zA-Z0-9,._\+\()\-],$filename)) { //blah, blah, blah } However, when I run the script I get the following error: Warning: Compilation failed: unmatched parentheses at offset 17 in /home/httpd/sigmarapid/html/test/upload.php on line 137 (the line with the preg_match) I'm new to regular expressions so any help would be greatly appreciated. Luis R. Lebron Sigmatech, Inc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg match compilation error
* Thus wrote Marek Kilimajer ([EMAIL PROTECTED]): Do you realy want to use [ and ] as patern delimiters? My quess is that you want to use it for defining character class. Then the only character that must be escaped is - '/[^a-z0-9,._+()\-]/i' actually, you don't even need that escape. It has the exception of being the range character if it is either the first or last character in the class. Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg match question
I am passing a string and making sure all the characters in that string are valid. Example: For a persons age I am using: if (!preg_match(/^[0-9]+$/, $Age)) echo Enter numeric value for age. But how would I include the following characters as permissible in preg match ~!@#$%^*()-=_+,.?/\|{}[] since some of these characters have special meaning in PCRE regrex syntax?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]