Re: [PHP] Preg Match Problem
On Wed, 2 Jun 2010 12:14:47 -0400 Alice Wei 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 Mon, Tue"; >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 -- 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 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 > -- > > WWW: http://plphp.dk / http://plind.dk > LinkedIn: http://www.linkedin.com/in/plind > BeWelcome/Couchsurfing: Fake51 > Twitter: http://twitter.com/kafe15 > _ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4
Re: [PHP] Preg Match Problem
On 2 June 2010 18:14, Alice Wei 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 -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- 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 Mon, Tue"; 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
[PHP] preg-replace-callback problem
In url http://www.php.net/manual/en/function.preg-replace-callback.php I read this example: '.$input[1].'';}return preg_replace_callback($regex, 'parseTagsRecursive', $input);}$output = parseTagsRecursive($input);echo $output;?> example does not work if there are more deep statement in var I mean if $input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain plain [indent] deep [indent] deeper [/indent] deep [/indent] plain "; it does not work corectly how can I solve this problem _ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
Re: [PHP] preg for unicode strings?
On Sat, November 5, 2005 3:02 pm, Andy Pieters wrote: > Hi List > > I am doing some data validation and the following regexp fails > > [\W] > > When using characters like £ or ⬠> > Obviously because they are technically more then one character, even > though > they are only displayed as one. > > The script is encoded in UTF-8 > > Anybody know a fix for this? You could use http://php.net/utf8_decode on it first, and then validate... I dunno if that would allow any nasties to get past, but it least it should validate the input as "legal" I think... I always feel overwhelmed by all this multi-lingual character-encoding multi-byte stuff, frankly. -- 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
Re: [PHP] preg for unicode strings?
Andy, try that one: /^[a-zA-Z]{3}|\p{Sc}$/u You don't want to put \p{Sc} in square brackets as \p{Sc} itself already is a character class. Umm.. Kinda don't make myself clear here, do I? You just don't want to, it's 5am in the morning here I gotta go to the next bed ;p Regards, Niels Andy Pieters: > Hi > > Thank you for your reply. > > My regexp was > > /^([a-zA-Z]{3,}|[\W])/ > > Meaning match any string that is either > 3 letters > or > 1 word character > > I'd like to change this to > 3 letters > or > 1 currency character > > So I changed the regexp accordingly > /^([a-zA-Z]{3,}|[\p{Sc}])/u > > And I tested with £ > > but it fails. > > Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg for unicode strings?
Hi Thank you for your reply. My regexp was /^([a-zA-Z]{3,}|[\W])/ Meaning match any string that is either 3 letters or 1 word character I'd like to change this to 3 letters or 1 currency character So I changed the regexp accordingly /^([a-zA-Z]{3,}|[\p{Sc}])/u And I tested with £ but it fails. Any ideas? With kind regards Andy On Sunday 06 November 2005 02:11, Niels Ganser wrote: > Andy, > > you might want to check out > http://www.regular-expressions.info/unicode.html > > Please note two things while using the described syntax: > 1. You have to additionally use the u modificator. > 2. While \p{Ll} for instance works in PHP, \p{Lowercase_Letter} doesn't. > > Regards, > Niels > > > Hi List > > > > I am doing some data validation and the following regexp fails > > > > [\W] > > > > When using characters like £ or € > > > > Obviously because they are technically more then one character, even > > though they are only displayed as one. > > > > The script is encoded in UTF-8 > > > > Anybody know a fix for this? > > > > With kind regards > > > > > > Andy -- Now listening to Top! Radio Live www.topradio.be/stream on amaroK Geek code: www.vlaamse-kern.com/geek Registered Linux User No 379093 If life was for sale, what would be its price? www.vlaamse-kern.com/sas/ for free php utilities -- pgpT8ldDDW3eO.pgp Description: PGP signature
Re: [PHP] preg for unicode strings?
Andy, you might want to check out http://www.regular-expressions.info/unicode.html Please note two things while using the described syntax: 1. You have to additionally use the u modificator. 2. While \p{Ll} for instance works in PHP, \p{Lowercase_Letter} doesn't. Regards, Niels > Hi List > > I am doing some data validation and the following regexp fails > > [\W] > > When using characters like £ or € > > Obviously because they are technically more then one character, even > though they are only displayed as one. > > The script is encoded in UTF-8 > > Anybody know a fix for this? > > With kind regards > > > Andy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg for unicode strings?
On 11/5/05, Andy Pieters <[EMAIL PROTECTED]> wrote: > > I am doing some data validation and the following regexp fails > [\W] > When using characters like £ or € > The script is encoded in UTF-8 Are you using the 'u' modifier to put PCRE in utf-8 mode? preg_match( '/\W/u', $text); -robin
[PHP] preg for unicode strings?
Hi List I am doing some data validation and the following regexp fails [\W] When using characters like £ or € Obviously because they are technically more then one character, even though they are only displayed as one. The script is encoded in UTF-8 Anybody know a fix for this? With kind regards Andy -- Now listening to The Prophet - I Can't Stand It on amaroK Geek code: www.vlaamse-kern.com/geek Registered Linux User No 379093 If life was for sale, what would be its price? www.vlaamse-kern.com/sas/ for free php utilities -- pgpgretkqqhNR.pgp Description: PGP signature
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 ? > > > $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 $msg"; > 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.."; > } > > } > 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
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 ? "; 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.."; } } mysql_close($dblink); ?> thanx in advance, chandana
Re: [PHP] preg guru again.....
On Mon, 2004-02-23 at 11:36, pete M wrote: > Here is a snippet > ð:2002020720020208:[EMAIL > PROTECTED]://www.lyricsworld.com/cgi-bin/search.cgi?q=Bruce > +Springsteen&m=phrase&ps=20&o=0&wm=wrd&ul=&wf=1ðððð > > it breaks down in the following elements > the :date: in the format mmddmmdd > The expression I'm using is > (":16[0-9]:") > ie matching the : with 16 digits : here's a start: /:(\d+):([EMAIL PROTECTED])@([\w&=+\/:\\%-]+)/i -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg guru again.....
Am trying to do a strange thing with php.. Extract the urls from the Internet Explorer index.dat history files (dont ask why!) Here is a snippet ð:2002020720020208:[EMAIL PROTECTED]://www.lyricsworld.com/cgi-bin/search.cgi?q=Bruce +Springsteen&m=phrase&ps=20&o=0&wm=wrd&ul=&wf=1ðððð it breaks down in the following elements the :date: in the format mmddmmdd The expression I'm using is (":16[0-9]:") ie matching the : with 16 digits : I'm using to match the url part (taken from php manual - thanks).. however am getting all the illegal characters - nulls, binary, etc back as its a binary file preg_match("/^(.*:\/\/)?([^:\/]+):?([0-9]+)?(.*)/", $contents, $match); also I want to allow / ~ ? & characters as well as http: file: protocols Complete string is preg_match(":16[0-9]:/^(.*:\/\/)?([^:\/]+):?([0-9]+)?(.*)/", $contents, $match); Of course it doesnt work !!! any help would be appreciated Pete -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg guru question
On Fri, 2004-02-13 at 13:25, pete M wrote: > Im trying to scan a file and lift the image name from the > ie > > where there could be ' or " > > I messed around but am 2 embarassed to post code cos it dont work ;-( Always post code, it can help us understand what you are looking to do. Are you looking for a regexp? '//i' -- Adam Bregenzer [EMAIL PROTECTED] http://adam.bregenzer.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg guru question
On Fri, Feb 13, 2004 at 02:19:11PM -0500, joel boonstra wrote: > if (preg_match('//ig', $dah, $matches)) { > print_r($matches); > } Doh! The '/ig' should just be '/i'. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg guru question
On Sat, Feb 14, 2004 at 03:05:40AM +0800, Jason Wong wrote: > $doo[1] = ''; > $doo[2] = ""; > > foreach ($doo as $dah) { > if (preg_match('//i', $dah, $matches)) { > print_r($matches); > } > } Note that characters within square brackets don't need to have the | to separate them; it's a character class, so it will match any character within the brackets: if (preg_match('//i', $dah, $matches)) { Also, it's probably good to put a non-greedy modifier after the *s to prevent .* from matching too much. Compare: '; $doo[2] = ""; foreach ($doo as $dah) { if (preg_match('//i', $dah, $matches)) { print_r($matches); } # adding ? after the * if (preg_match('//ig', $dah, $matches)) { print_r($matches); } } ?> 'Course, it still doesn't match multiple images in one line. preg_match_all() could probably help out there. joel -- [ joel boonstra | gospelcom.net ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg guru question
On Saturday 14 February 2004 02:25, pete M wrote: > Im trying to scan a file and lift the image name from the > ie > > where there could be ' or " > > I messed around but am 2 embarassed to post code cos it dont work ;-( It's always better to post something no matter how bad you may think it is. It shows that you have at least tried to solve your own problem and are not merely trying to earn your keep by asking others to do your work for you. Here's something to get you started: $doo[1] = ''; $doo[2] = ""; foreach ($doo as $dah) { if (preg_match('//i', $dah, $matches)) { print_r($matches); } } You may want to refine it so that it will recognise less than perfectly formed tags. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Knowledge, sir, should be free to all! -- Harry Mudd, "I, Mudd", stardate 4513.3 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg guru question
Im trying to scan a file and lift the image name from the ie where there could be ' or " I messed around but am 2 embarassed to post code cos it dont work ;-( thanks in advance pete -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preg Replace
On Tuesday 06 January 2004 12:35, Aaron Axelsen wrote: > I am fighting replacing items in the following hunk of code. This code is > pulled from a database, and then I want to replace items like <> with > the contents of a variable $name. > > I have tried code like: > preg_replace("/\<\<\?.*?\>\>/",$name,$paypal); The angle brackets have no special meaning so there's no need to escape them. Something like: preg_replace('/(<<.*>>)/U', $name, $paypal); should work. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* Time is an illusion, lunchtime doubly so. -- The Hitchhiker's Guide to the Galaxy */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preg Replace
Hello, I am fighting replacing items in the following hunk of code. This code is pulled from a database, and then I want to replace items like <> with the contents of a variable $name. I have tried code like: preg_replace("/\<\<\?.*?\>\>/",$name,$paypal); However it doesn't work, any suggestions are appreciated. Thanks. Here is the chunk code: -- Aaron Axelsen AIM: aaak2 Email: [EMAIL PROTECTED]
RE: [PHP] preg question
> -Original Message- > From: zhuravlev alexander [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 13, 2003 3:26 PM > To: Jake McHenry > Cc: 'John Nichel'; [EMAIL PROTECTED] > Subject: Re: [PHP] preg question > > > On Thu, Nov 13, 2003 at 03:17:14PM -0500, Jake McHenry wrote: > > What else would I need to check for? I'm tired.. Running on > 2 pots of > > coffee.. All I can think of is the @ and at least one . > After the @, > > then at least 2 characters after the last . > > > > I haven't had much experience with regular expresssions, all of the > > stuff I've done has been for my intranet, and I didn't > really need to > > validate.. Now I'm on a project where it's public > http://www.zend.com/codex.php?id=861&single=1 http://www.zend.com/codex.php?id=88&single=1 Wow, thanks for the links... That definatly speeds things up a little for me. Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg question
On Thu, Nov 13, 2003 at 03:17:14PM -0500, Jake McHenry wrote: > What else would I need to check for? I'm tired.. Running on 2 pots of > coffee.. All I can think of is the @ and at least one . After the @, > then at least 2 characters after the last . > > I haven't had much experience with regular expresssions, all of the > stuff I've done has been for my intranet, and I didn't really need to > validate.. Now I'm on a project where it's public http://www.zend.com/codex.php?id=861&single=1 http://www.zend.com/codex.php?id=88&single=1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg question
What else would I need to check for? I'm tired.. Running on 2 pots of coffee.. All I can think of is the @ and at least one . After the @, then at least 2 characters after the last . I haven't had much experience with regular expresssions, all of the stuff I've done has been for my intranet, and I didn't really need to validate.. Now I'm on a project where it's public Thanks for the help Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com > -Original Message- > From: John Nichel [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 13, 2003 3:09 PM > To: Jake McHenry > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] preg question > > > Jake McHenry wrote: > > >>-Original Message- > >>From: Jake McHenry [mailto:[EMAIL PROTECTED] > >>Sent: Thursday, November 13, 2003 2:50 PM > >>To: [EMAIL PROTECTED] > >>Subject: [PHP] preg question > >> > >> > >>Hi all, > >> > >>I am trying to do a simple validation of an email address > >>being submitted. I have the @ sign being validated, but I > >>can't get the period to work.. Can someone help me out? > >> > >>Here's my code.. > >> > >>if ($_POST['Travel_Request_Email_Address'] != "") > >>{ > >> if (preg_match_all("/(@)/", > >>$_POST['Travel_Request_Email_Address'], $match) != 1) > >> { > >>$errorcount++; > >>$error = $error . "" . > >>$errorcount .") Email Address > >>field does not contain @ \n"; > >> } > >> else if (preg_match_all("/(.)/", > >>$_POST['Travel_Request_Email_Address'], $match) < 1) > >> { > >>$errorcount++; > >>$error = $error . "" . > >>$errorcount .") Email Address > >>field does not contain . \n"; > >> } > >> else > >> { > >>$_SESSION['Travel_Request_Email_Address'] = > >>$_POST['Travel_Request_Email_Address']; > >> } > >>} > >>else > >>{ > >> $errorcount++; > >> $error = $error . "" . > >>$errorcount .") Email Address > >>field is empty\n"; > >>} > >> > >>Thanks, > >> > >>Jake McHenry > >>Nittany Travel MIS Coordinator > >>http://www.nittanytravel.com > >> > >>-- > >>PHP General Mailing List (http://www.php.net/) > >>To unsubscribe, visit: http://www.php.net/unsub.php > >> > >> > > > > > > > > I think I got it, I was just messing with the code, and > added a slash > > before the ., and it seems to work. Is this the correct way > to handle > > this? > > Yes, you have to escape the period. If you're just checking > to see if > there's an at symbol and a period, you don't really need > preg_match_all > > if ( ! preg_match ( "/@/", $email ) ) { > // No @ symbol > } > if ( ! preg_match ( "/\./", $email ) ) { > // No period > } > > -- > By-Tor.com > It's all about the Rush > http://www.by-tor.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg question
The period is a modifier within the expression (see manual on "pattern syntax" link below). You need to escape it with a back slash: \. http://www.php.net/manual/en/pcre.pattern.syntax.php -- Kevin -Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 12:50 PM To: [EMAIL PROTECTED] Subject: [PHP] preg question Hi all, I am trying to do a simple validation of an email address being submitted. I have the @ sign being validated, but I can't get the period to work.. Can someone help me out? Here's my code.. if ($_POST['Travel_Request_Email_Address'] != "") { if (preg_match_all("/(@)/", $_POST['Travel_Request_Email_Address'], $match) != 1) { $errorcount++; $error = $error . "" . $errorcount .") Email Address field does not contain @ \n"; } else if (preg_match_all("/(.)/", $_POST['Travel_Request_Email_Address'], $match) < 1) { $errorcount++; $error = $error . "" . $errorcount .") Email Address field does not contain . \n"; } else { $_SESSION['Travel_Request_Email_Address'] = $_POST['Travel_Request_Email_Address']; } } else { $errorcount++; $error = $error . "" . $errorcount .") Email Address field is empty\n"; } Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- 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 question
Jake McHenry wrote: -Original Message- From: Jake McHenry [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 2:50 PM To: [EMAIL PROTECTED] Subject: [PHP] preg question Hi all, I am trying to do a simple validation of an email address being submitted. I have the @ sign being validated, but I can't get the period to work.. Can someone help me out? Here's my code.. if ($_POST['Travel_Request_Email_Address'] != "") { if (preg_match_all("/(@)/", $_POST['Travel_Request_Email_Address'], $match) != 1) { $errorcount++; $error = $error . "" . $errorcount .") Email Address field does not contain @ \n"; } else if (preg_match_all("/(.)/", $_POST['Travel_Request_Email_Address'], $match) < 1) { $errorcount++; $error = $error . "" . $errorcount .") Email Address field does not contain . \n"; } else { $_SESSION['Travel_Request_Email_Address'] = $_POST['Travel_Request_Email_Address']; } } else { $errorcount++; $error = $error . "" . $errorcount .") Email Address field is empty\n"; } Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php I think I got it, I was just messing with the code, and added a slash before the ., and it seems to work. Is this the correct way to handle this? Yes, you have to escape the period. If you're just checking to see if there's an at symbol and a period, you don't really need preg_match_all if ( ! preg_match ( "/@/", $email ) ) { // No @ symbol } if ( ! preg_match ( "/\./", $email ) ) { // No period } -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg question
> -Original Message- > From: Jake McHenry [mailto:[EMAIL PROTECTED] > Sent: Thursday, November 13, 2003 2:50 PM > To: [EMAIL PROTECTED] > Subject: [PHP] preg question > > > Hi all, > > I am trying to do a simple validation of an email address > being submitted. I have the @ sign being validated, but I > can't get the period to work.. Can someone help me out? > > Here's my code.. > > if ($_POST['Travel_Request_Email_Address'] != "") > { > if (preg_match_all("/(@)/", > $_POST['Travel_Request_Email_Address'], $match) != 1) > { > $errorcount++; > $error = $error . "" . > $errorcount .") Email Address > field does not contain @ \n"; > } > else if (preg_match_all("/(.)/", > $_POST['Travel_Request_Email_Address'], $match) < 1) > { > $errorcount++; > $error = $error . "" . > $errorcount .") Email Address > field does not contain . \n"; > } > else > { > $_SESSION['Travel_Request_Email_Address'] = > $_POST['Travel_Request_Email_Address']; > } > } > else > { > $errorcount++; > $error = $error . "" . > $errorcount .") Email Address > field is empty\n"; > } > > Thanks, > > Jake McHenry > Nittany Travel MIS Coordinator > http://www.nittanytravel.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I think I got it, I was just messing with the code, and added a slash before the ., and it seems to work. Is this the correct way to handle this? Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg question
Hi all, I am trying to do a simple validation of an email address being submitted. I have the @ sign being validated, but I can't get the period to work.. Can someone help me out? Here's my code.. if ($_POST['Travel_Request_Email_Address'] != "") { if (preg_match_all("/(@)/", $_POST['Travel_Request_Email_Address'], $match) != 1) { $errorcount++; $error = $error . "" . $errorcount .") Email Address field does not contain @ \n"; } else if (preg_match_all("/(.)/", $_POST['Travel_Request_Email_Address'], $match) < 1) { $errorcount++; $error = $error . "" . $errorcount .") Email Address field does not contain . \n"; } else { $_SESSION['Travel_Request_Email_Address'] = $_POST['Travel_Request_Email_Address']; } } else { $errorcount++; $error = $error . "" . $errorcount .") Email Address field is empty\n"; } Thanks, Jake McHenry Nittany Travel MIS Coordinator http://www.nittanytravel.com -- 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
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 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
[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[2]: [PHP] preg help please :)
Hi, Friday, October 17, 2003, 10:26:40 AM, you wrote: JF> On Thursday, October 16, 2003, at 04:32 PM, Eugene Lee wrote: >> Try inverting the greediness with a "U" pattern modifier: >> >> "/$quote(.*)$quote:$quote(.*)$quote/U" >> >> For more details: >> >> http://www.php.net/manual/en/pcre.pattern.modifiers.php >> JF> Nope -- didn't help sorry... if there's two links in a block of text, JF> it will match from the start of the first one all the way through to JF> the end of the second one. JF> I think I need: JF> "/$quote(*)$quote:$quote(*)$quote/" JF> Where is substituted for the correct expression -- but my JF> skills aren't there yet :) JF> Justin I think you need (.*?) to stop the * being greedy, but I am no guru on this martian language either. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg help please :)
On Thursday, October 16, 2003, at 04:32 PM, Eugene Lee wrote: Try inverting the greediness with a "U" pattern modifier: "/$quote(.*)$quote:$quote(.*)$quote/U" For more details: http://www.php.net/manual/en/pcre.pattern.modifiers.php Nope -- didn't help sorry... if there's two links in a block of text, it will match from the start of the first one all the way through to the end of the second one. I think I need: "/$quote(*)$quote:$quote(*)$quote/" Where is substituted for the correct expression -- but my skills aren't there yet :) Justin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg help please :)
On Thu, Oct 16, 2003 at 02:23:45PM +1000, Justin French wrote: : : I have the following: : : \\1", : $text : ); : ?> : : It basically matches "link text":"url" with the added twist of having : the quotes converted to “ or “ by a previous function. : : It works fine if there is one link found inside a string, but falls : over horribly if there's two links inside a string. : : How can I improve the (.*) to exclude $quote ? Try inverting the greediness with a "U" pattern modifier: "/$quote(.*)$quote:$quote(.*)$quote/U" For more details: http://www.php.net/manual/en/pcre.pattern.modifiers.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg help please :)
Hi, I have the following: \\1", $text ); ?> It basically matches "link text":"url" with the added twist of having the quotes converted to “ or “ by a previous function. It works fine if there is one link found inside a string, but falls over horribly if there's two links inside a string. How can I improve the (.*) to exclude $quote ? Thanks, Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg question
* Thus wrote Mike J ([EMAIL PROTECTED]): > How do I take that and put it into a variable like $title? print_r($matches) will answer that. Btw, I had a typo, it should have been: preg_match("/()(.*)(<\/\\2>)/i", $html, $matches); Not preg_match_all(). Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg question
* Thus wrote Mike J ([EMAIL PROTECTED]): > I want to pull the title (example) of a webpage out of some text. The > end result being "example". What preg function should I use and can someone give me > the the code that will do it? > preg_match is what you want. And if you poke around the preg_* section abit you'll see that preg_match_all has exactly what you want: /* match all content matches */ preg_match_all ("/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/", $html, $matches); Ahh.. but you say... I only want the title tag... so changing the regex to this: preg_match_all ("/()(.*)(<\/\\2>)/i", $html, $matches); Add the 'i' flag for case INsensitivity, you have your solution.. easy eh? I'll let ya do the rest :) HTH, 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 question
I want to pull the title (example) of a webpage out of some text. The end result being "example". What preg function should I use and can someone give me the the code that will do it? J. PS. I've been on php.net trying to figure it out. -- ___ Get your free Verizonmail at www.verizonmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PREG-pattern, help needed
Hi, What about: $string = preg_replace("/(]*/","\\1 id={$counter}",$string); atur - Original Message - From: "Tobias Talltorp" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 09, 2003 6:35 PM Subject: [PHP] PREG-pattern, help needed > I need help with a preg-pattern for preg_replace_callback(). > > I need to match and replace them with id=$counter>. > > This is as far as I have come in my code: > > > $html = ' > > > > > tabell2 cell1 > tabell2 cell2 > > > > första cell i rad två > Detta är den sista > > '; > > $counter = 0; > function bla($matches) { > global $counter; > $counter++; > return ""; > } > > > // this pattern is all wrong, since it matches and replaces all tags > echo preg_replace_callback("|(<[td][^>]+>)|i", "bla", $html); > > ?> > > > Any thoughts? > // Tobias > > -- > 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-pattern, help needed
I need help with a preg-pattern for preg_replace_callback(). I need to match and replace them with . This is as far as I have come in my code: tabell2 cell1 tabell2 cell2 första cell i rad två Detta är den sista '; $counter = 0; function bla($matches) { global $counter; $counter++; return ""; } // this pattern is all wrong, since it matches and replaces all tags echo preg_replace_callback("|(<[td][^>]+>)|i", "bla", $html); ?> Any thoughts? // Tobias -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg, patern quantifier limit
Hello, This is a reply to an e-mail that you wrote on Fri, 1 Aug 2003 at 20:35, lines prefixed by '>' were originally written by you. > Hi, i did a standard preg [A-Za-z0-9]{1,65536} > What i am simply trying to do is to validate the a form that will > insert > into my TEXT database field. So i just want to prevent a larger insert > then expected. > PHP trows me this error "preg_match(): Compilation failed: number too > big in {} quantifier at offset 19 ..." > So it appears that quantifiers are limited. Anybody knows what that > limit is ? I can't help with your actual question, but I just thought I would mention you can do what you are trying to do with... if(strlen($text)>65536){ // too big } http://php.net/strlen David. -- phpmachine :: The quick and easy to use service providing you with professionally developed PHP scripts :: http://www.phpmachine.com/ Professional Web Development by David Nicholson http://www.djnicholson.com/ QuizSender.com - How well do your friends actually know you? http://www.quizsender.com/ (developed entirely in PHP) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg, patern quantifier limit
* Thus wrote Yann Larrivee ([EMAIL PROTECTED]): > Hi, i did a standard preg [A-Za-z0-9]{1,65536} > > What i am simply trying to do is to validate the a form that will insert > into my TEXT database field. So i just want to prevent a larger insert > then expected. > > > PHP trows me this error "preg_match(): Compilation failed: number too > big in {} quantifier at offset 19 ..." > > > So it appears that quantifiers are limited. Anybody knows what that > limit is ? It looks like it should be 65535, which makes more sense because that is the unsigned word boundry. if you inisist on having a 65536 limit use strlen with the preg if (strlen($str) <= 65536 && preg_match('/[A-Za-z0-9]+/', $str)) { HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg, patern quantifier limit
Hi, i did a standard preg [A-Za-z0-9]{1,65536} What i am simply trying to do is to validate the a form that will insert into my TEXT database field. So i just want to prevent a larger insert then expected. PHP trows me this error "preg_match(): Compilation failed: number too big in {} quantifier at offset 19 ..." So it appears that quantifiers are limited. Anybody knows what that limit is ? Thanks -- Yann Larrivee <[EMAIL PROTECTED]> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg split question
> i'd like to split Benutzer_CRA.php > to get CRA but sometimes the files are called > Benutzer_OVE_CRA.php and therefore the result schould OVE_CRA > how cann i tell preg_split to split the string at the > first occurence of _ and before .php preg_match("/_(.*)\.php/",$str,$matches); $matches[1] will contain what you're looking for. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg split question
Torsten, You could use explode on the file name and then only read in the sections that you want: $FileName = "Benutzer_OVE_CRA.php"; $Part1 = explode("_", $FileName_); $TotalPart1 = count($Part1); $Wanted_File_Pieces = array(); // C = 2 so that it will skip the Benutzer part of the filename and will be equal to total before the end is reached. for ($C=2; $C<$TotalPart1; $C++) { $Wanted_File_Pieces[($C - 2)] = $Part1[($C - 1)]; } $Part2 = explode(".", $Part1[$TotalPart1]); $Total2 = count($Wanted_File_Pieces); $Wanted_File_Pieces[$Total2] = $Part2[0]; $NewFileName = join("_", $Wanted_File_Pieces); It may be possible to do it with preg_split, I am not as familiar with that function as I would like to be. Hope this helped show you another way to do what you where wanting to do. Jonathan Pitcher On Thursday, March 27, 2003, at 08:39 AM, Torsten Rosenberger wrote: Hello i'd like to split Benutzer_CRA.php to get CRA but sometimes the files are called Benutzer_OVE_CRA.php and therefore the result schould OVE_CRA how cann i tell preg_split to split the string at the first occurence of _ and before .php BR/Torsten -- 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 split question
Hello i'd like to split Benutzer_CRA.php to get CRA but sometimes the files are called Benutzer_OVE_CRA.php and therefore the result schould OVE_CRA how cann i tell preg_split to split the string at the first occurence of _ and before .php BR/Torsten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg help ?
// should work ... prob. a better way to do this but its functional :) -Peter > -Original Message- > From: :B nerdy [mailto:[EMAIL PROTECTED]] > Sent: Sunday, September 29, 2002 02:05 > To: [EMAIL PROTECTED] > Subject: [PHP] preg help ? > > > ive got a html document with the following string in it: > > > what i want to do is get the string which corresponds to > value. so that is > \oiXESASZC?~adQXZDQ?_ > > ive used > preg_match_all (' VALUE="(.*)">', > $contents,$out, PREG_PATTERN_ORDER); > > but it returns the whole document :( > > a little help? cheers > > > > -- > 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 help ?
ive got a html document with the following string in it: what i want to do is get the string which corresponds to value. so that is \oiXESASZC?~adQXZDQ?_ ive used preg_match_all ('', $contents,$out, PREG_PATTERN_ORDER); but it returns the whole document :( a little help? cheers -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preg replace & Query Problem
Hi, I'm having trouble with preg_replace and a mysql query. Here's my code : $query = $db->query("SELECT style FROM ".$table_styles." WHERE id = '1'"); $r = $db->fetch_array($query); $style_1 = $r[style]; $query = $db->query("SELECT id, name, description FROM ".$table_categories.""); while($r = $db->fetch_row($query)) { $category_id = $r[0]; $category_name = $r[1]; $category_description = $r[2]; $style_1 = preg_replace('/\[url\]/', "index.php?catID=$category_id", $style_1); $style_1 = preg_replace('/\[title\]/', "$category_name", $style_1); echo "$style_1\n"; echo "\n"; } This is the schema for $table_styles ++-+-+-- ---+ | id | name| description | style | ++-+-+-- ---+ | 1| Title Links | The style for the title links on the main page. | [title] | ++-+-+-- ---+ This is the schema for $table_categories ++--+--+---+ --+ | id | name | description | picture | comments | ++--+--+---+ --+ | 1 | PHP | PHP is a powerful open source language. | icon3.gif | 0 | | 2 | ASP | ASP is microsoft's dynamic web language.| icon2.gif | 0 | ++--+--+---+ --+ The script should loop and replace [url] and [title] with the relative id and name from $table_categories, however when it is run, it gives out : PHP PHP I'm really not sure what's going on, can anyone help me ? Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg help (regexp newbie) whitespace
On Tuesday 02 July 2002 10:06, Justin French wrote: > what's the correct pattern for "one or more whitespaces" (including \n\r\t > and anything else I'm missing)? I prefer the PCRE so: \s+ > what about "zero or more whitespaces"? \s* It's all in the manual! -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Everyone can be taught to sculpt: Michelangelo would have had to be taught how ___not to. So it is with the great programmers. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg help (regexp newbie) whitespace
Hi all, what's the correct pattern for "one or more whitespaces" (including \n\r\t and anything else I'm missing)? what about "zero or more whitespaces"? Thanks in advance, Justin French -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg and Perl 6 (upcoming..not current preg handling)
We are using the PCRE library for this. I don't think there are any plans to drop the Perl5 syntax. On Wed, 26 Jun 2002, Peter Thoenen wrote: > Anybody know if PHP 4.x (5.x?) will be sticking with > Perl5 RegEx syntax for preg's or will it be changing > to the new Perl6 RegEx syntax (which I really dislike > but what can you do, Larry has spoken). > > If we do plan to move to Perl6 RegEx, please implement > the P5 modifier > > -Peter > > __ > Do You Yahoo!? > Yahoo! - Official partner of 2002 FIFA World Cup > http://fifaworldcup.yahoo.com > > -- > 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 and Perl 6 (upcoming..not current preg handling)
Anybody know if PHP 4.x (5.x?) will be sticking with Perl5 RegEx syntax for preg's or will it be changing to the new Perl6 RegEx syntax (which I really dislike but what can you do, Larry has spoken). If we do plan to move to Perl6 RegEx, please implement the P5 modifier -Peter __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg
Sounds like a weird thing to want to do, but this will do it: preg_replace('/(\w)\1$/','2',$str) -Rasmus On Wed, 12 Jun 2002, Zac Hillier wrote: > Does anyone know how I can use preg or any other function to identify a > double letter on the end of a string and then replace it. > > So 'foo' would become 'f2' and 'bar' would not change. > > Thanks > > Zac > > > -- > 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
Does anyone know how I can use preg or any other function to identify a double letter on the end of a string and then replace it. So 'foo' would become 'f2' and 'bar' would not change. Thanks Zac -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preg Match
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 "Please 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]
[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]
Re: [PHP] PREG
Hi Matt, first it might be easier to just use split here -- $fields = split("\t",$line); I say might because I suspect that the records you have that are converting incorrectly perhaps don't follow the tab convention? ... said another way, I've never seen preg break because the file got over a meg in size;) On Fri, Dec 07, 2001 at 11:50:51PM -, Matthew Moreton wrote: > Hi people. I am having some trouble with the PREG functions in php. > > Here's what I am trying to do... > > First of all I am reading in a file which is 1.5mb's in size, it could be many more, >going up to 8mb's, the contents of the file is input to a string. > > The format of the file is as follows... > > ###"quoted text""quoted text"## > > the # represents a number, in the case of the first 3 numbers they are only ever 1 >or 2 digits long. The final two digits can get to be rather big in size, thousands >and millions. Each element is seperated by a tab space and then a carriage return >(\r) terminates each record. > > I use preg_match_all to find all the lines that start with 1 and 1 as there first >numbers, typically there will be 25 entries of 1 1. So I am looking for all lines in >this format: > > 11#"quoted text""quoted text"## > > I have the search pattern figured out, it is as follow: > > >preg_match_all("/($first)\t($second)\t([0-9]{1,2})\t\"([^\"]*)\"\t\"([^\"]*)\"\t([0-9]*)\t([0-9]*)\r/", > $input, $output, PREG_SET_ORDER ); > > When this pattern finds a matching line beginning equal to $first and $second it >will put all the elements of the record into the array $output. $output[0] being the >array of the first elements found, $array[1] being the second line that was matched, >and so on. > > This pattern does actually work to some extent. When the filesize is low (100kb) it >works fine, but when I start to get over that filesize it becomes greedy and the >$second value doesnt seem to be taken into account when it searchs. It seems to >return everything that equals the following: > > 1##"quoted text""quoted text"## > > Obviously not what I want. Could this be some sort of overflow problem? I am at a >lost end here, so if anyone could offer some insight as to why it is not functioning >correctly I would most welcome it. Overwise the only solution I can think of is >chopping up the input, I dont really want to go down that path, as it seems like a >rather cheap workaround. > > Thanks. > > Matt -- Hank Marquardt <[EMAIL PROTECTED]> http://web.yerpso.net GPG Id: 2BB5E60C Fingerprint: D807 61BC FD18 370A AC1D 3EDF 2BF9 8A2D 2BB5 E60C *** Web Development: PHP, MySQL/PgSQL - Network Admin: Debian/FreeBSD *** PHP Instructor - Intnl. Webmasters Assn./HTML Writers Guild *** Beginning PHP -- Starts January 7, 2002 *** See http://www.hwg.org/services/classes -- 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]
[PHP] PREG
Hi people. I am having some trouble with the PREG functions in php. Here's what I am trying to do... First of all I am reading in a file which is 1.5mb's in size, it could be many more, going up to 8mb's, the contents of the file is input to a string. The format of the file is as follows... ###"quoted text""quoted text"## the # represents a number, in the case of the first 3 numbers they are only ever 1 or 2 digits long. The final two digits can get to be rather big in size, thousands and millions. Each element is seperated by a tab space and then a carriage return (\r) terminates each record. I use preg_match_all to find all the lines that start with 1 and 1 as there first numbers, typically there will be 25 entries of 1 1. So I am looking for all lines in this format: 11#"quoted text""quoted text"## I have the search pattern figured out, it is as follow: preg_match_all("/($first)\t($second)\t([0-9]{1,2})\t\"([^\"]*)\"\t\"([^\"]*)\"\t([0-9]*)\t([0-9]*)\r/", $input, $output, PREG_SET_ORDER ); When this pattern finds a matching line beginning equal to $first and $second it will put all the elements of the record into the array $output. $output[0] being the array of the first elements found, $array[1] being the second line that was matched, and so on. This pattern does actually work to some extent. When the filesize is low (100kb) it works fine, but when I start to get over that filesize it becomes greedy and the $second value doesnt seem to be taken into account when it searchs. It seems to return everything that equals the following: 1##"quoted text""quoted text"## Obviously not what I want. Could this be some sort of overflow problem? I am at a lost end here, so if anyone could offer some insight as to why it is not functioning correctly I would most welcome it. Overwise the only solution I can think of is chopping up the input, I dont really want to go down that path, as it seems like a rather cheap workaround. Thanks. Matt
[PHP] preg vs ereg (performance)
I am in the process of writing an application that does a lot of parsing in which performance is the key. In the process, I performed some rudimentary speed testing that yielded some interesting results. Rather than keep them to myself, I thought I would share them. I am currently parsing out the contents of general webpages, so for the test case, I used a string that contained the html to generate a fairly standard select list (with 31 options). For the first test, I merely wanted to pull out the name of the select element. I used the following two parsing commands in a side-by-side timing comparison and ran each in a loop 5000 times to get a larger time value: preg_match( "/name=[ ]?(['\"])?((?(1)[^\\1]|[^\s\>])+?)(?(1)\\1|[\s>])/i", $string, $arr ); eregi( "name=[\"']{0,1}([_0-9a-zA-Z]+)[\"']{0,1}", $string, $arr ); Note: The preg_match expression is actually far more accurate that the eregi as well as complex. It handles the case of "name=34 multiple>" as well as "name='my select'". Both expressions were also case insensitive. The results: preg_match Timer: This page was generated in 0.26572799682617 seconds. eregi Timer: This page was generated in 1.2171900272369 seconds. The preg_match is considerably faster than ereg and much more powerful (the PHP homepage for the documentation), and while the syntax takes a little adjustment (if you have never used Perl before), it is not that difficult to convert to. When I replaced all of my eregi statements with their preg_match equivalents, I found that the parsing portion of my page went from .46 seconds to .23. When it comes to regular expression pattern matching, I have come to the conclusion that the only option is preg_match. Inspired by this revelation, I decided to test preg_split vs split vs explode. It was not nearly as interesting, but I thought I would post my results nonetheless. Using the same string as above, I decided to split the string by the ", $string, $arr ); explode( "", $string, $arr ); The results: preg_split Timer: This page was generated in 0.23138296604156 seconds. split Timer: This page was generated in 0.22009003162384 seconds. explode Timer: This page was generated in 0.14973497390747 seconds. This really is not too surprising when it comes to explode. If there is no complex pattern matching, always use explode. preg_split vs split was a little surprising given my findings above, but in general, it looks like while there is not much of a difference, split has the slight edge. Summary: * If you are doing regular expression matching in a string, use preg_match. Not only is it much faster, but it is much more powerful than ereg. * If you are splitting a string by a simple string pattern, use explode. * If you are splitting a string using regular expressions, use split unless you need the functionality of preg_split. Disclaimer: I have not done exhaustive performance study of all of the possible scenarios to find discrepancies, but from my observations so far, the above conclusions have held true. If anyone has any other information, please post it for us all to share. I hope some of you have found this useful. Matthew Aznoe Fuzz Technologies [EMAIL PROTECTED] (406) 587-1100 x217 -- 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]
Re: [PHP] preg question
"Michael Geier" <[EMAIL PROTECTED]> wrote: > What I need to find is all the urls in the document and make hrefs out of > them. > > ie: > http://www.mysite.com becomes href="http://www.mysite.com">http://www.mysite.com; > > any ideas? TIA! I use this code in my PHPost project: $s = ereg_replace("([[:alpha:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "\\0", $s ); Mark -- 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]
[PHP] preg question
on http://www.php.net/manual/en/function.preg-match-all.php there is a regex: $url = "http://www.catho.com.br/index.phtml"; $contents = Implode("", File($url)); preg_match_all("|href=\"?([^\"' >]+)|i", $contents, $arrayoflinks); While(List(,$link) = Each($arrayoflinks[1])) Echo "$link"; that pulls allthe urls out of a document by finding the href=. What I need to find is all the urls in the document and make hrefs out of them. ie: http://www.mysite.com becomes http://www.mysite.com; any ideas? TIA! Michael Geier CDMSports Systems Administration EMail: [EMAIL PROTECTED] Phone: 314.991.1511 x 6505 -- 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]