Re: [PHP] help with preg_match
On 2012-06-03 22:37, Robert Williams wrote: On Jun 3, 2012, at 17:28, Chris Purvesch...@northfolk.ca wrote: I know that the text ends 'end', but I don't know what the Something, something is. I am using preg_match as follows: preg_match('/[^]*end/',$curl_response,$matches); I want to match 'end' and everything before it that is not ''. You need to match something at the beginning. Try this: preg_match('/([^]*end)/', $curl_response, $matches); Assuming a match, you can then look to $matches[1] for your content. That did it. In my case, I know that the first letter is capitalized, so I used: preg_match('/[A-Z][^]*end/', $curl_response, $matches); Thanks for your help. -- Chris Purves The eyes are the groin of the head. Dwight Schrute -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] help with preg_match
Hello, I am trying to use preg_match to match something from an html file. Within the html file is some text that looks like: spanSomething, something end/span I know that the text ends 'end', but I don't know what the Something, something is. I am using preg_match as follows: preg_match('/[^]*end/',$curl_response,$matches); I want to match 'end' and everything before it that is not ''. The problem appears to be with the ''. I have tried escaping (\), but it didn't make a difference. The php script hangs when it tries to run this function. -- Chris Purves There's a time to think, and a time to act. And this, gentlemen, is no time to think. - Sheriff Bud B. Boomer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with preg_match
On Jun 3, 2012, at 17:28, Chris Purves ch...@northfolk.ca wrote: I know that the text ends 'end', but I don't know what the Something, something is. I am using preg_match as follows: preg_match('/[^]*end/',$curl_response,$matches); I want to match 'end' and everything before it that is not ''. You need to match something at the beginning. Try this: preg_match('/([^]*end)/', $curl_response, $matches); Assuming a match, you can then look to $matches[1] for your content. -- Bob Williams Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] help with preg_match
-Original Message- From: Chris Purves [mailto:ch...@northfolk.ca] Sent: Sunday, June 03, 2012 8:26 PM To: php-general General Subject: [PHP] help with preg_match Hello, I am trying to use preg_match to match something from an html file. Within the html file is some text that looks like: spanSomething, something end/span I know that the text ends 'end', but I don't know what the Something, something is. I am using preg_match as follows: preg_match('/[^]*end/',$curl_response,$matches); I want to match 'end' and everything before it that is not ''. The problem appears to be with the ''. I have tried escaping (\), but it didn't make a difference. The php script hangs when it tries to run this function. -- Chris Purves There's a time to think, and a time to act. And this, gentlemen, is no time to think. - Sheriff Bud B. Boomer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- You could try this preg_match_all('/(span[^]**)(.*)(/span[^]*)/is',$curl_response,$matc hes); print_r($matches); Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with preg_match and windows domain logins...
I'm trying to do what should be a very simple regex, but can't seem to get PHP to work, yet regex-coach and even an XML .XSD work fine: Valid forms of a windows logon are: foo\bar \\foo\bar function isValidWinLogon($logon) { //$logon = 'foo\\bar'; $logon = '\\foo\bar'; print PPRElogon = '$logon'BR/PRE\n; preg_match('/()?.+\\.+/', $logon, $matches); //preg_match('/()?.+(\\).+/', $logon, $matches); print_r($matches); return (count($matches) 0); } I'm obviously passing in the strings, but for testing, I tried to hard-code it. First, when I use single ticks, I thought that meant to be taken literally. Seems I still have to escape (\) the backslashes. In either case, the $matches array is EMPTY. Further more, WTF do I get this error: Compilation failed: missing ) at offset 12 (pointing to the commented out preg_match. WTF should adding a set of parenthesis cause a compilation error?! # php -v PHP 5.0.3 (built: Dec 1 2005 02:20:49) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies with Zend Extension Manager v1.0.9, Copyright (c) 2003-2005, by Zend Technologies with Zend Optimizer v2.6.0, Copyright (c) 1998-2005, by Zend Technologies -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with preg_match and windows domain logins...
On 12/13/05, Daevid Vincent [EMAIL PROTECTED] wrote: I'm trying to do what should be a very simple regex, but can't seem to get PHP to work, yet regex-coach and even an XML .XSD work fine: Valid forms of a windows logon are: foo\bar \\foo\bar [...] //preg_match('/()?.+(\\).+/', $logon, $matches); [...] Further more, WTF do I get this error: Compilation failed: missing ) at offset 12 (pointing to the commented out preg_match. WTF should adding a set of parenthesis cause a compilation error?! WTF do you need so many WTFs? Adding a set of parenthesis isn't causing the error. Adding an open-bracket and then an escaped close-bracket is causing your error. The missing ) at offset 12 is a bit of a clue there. Backslashes are special characters to both single-quoted strings AND regular expressions so if you use them, you're normally going to have to escape them twice. So if you want optional double backslashes, followed by any characters followed by a backslash followed by any characters - which is what I'm guessing you were aiming at, you'd start off with this: /^(\\)?.+\.+$/ you need to escape the backslashes for the regular expression engine so you get this: /^()?.+\\.+$/ and you're supplying it in a single-quoted string, which also needs the backslashes escaped, so you get this: '/^()?.+.+$/' by which point you should be swearing at Microsoft for choosing such a stupid character for a login string delimiter. Clear? -robin
[PHP] help with preg_match
Hi, I'm trying to write a function that validates the input in a textarea. I just want to allow alphanumrical characters, and if the user enters anything else, I display an error message by calling error(). But the following doesn't work. Even if I enter hello in the textarea, I get the error message. What am I missing? // validate entered text in textarea function validate_textarea($unchecked_text) { if (!preg_match (/^[a-zåäö0-9]$/is, $unchecked_text)) { error(You have used unlegal characters, just alphanumeric is ok.); } } Best regards, Anders -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] help with preg_match
You need to tell preg_match that there will be multiple characters. Right now, you're searching for one, and only one. if (! preg_match ('/^[a-z0-9]+$/', $unchecked_text)) { The + means one or more matches to the range in brackets. -- tracy On 1/4/03 9:03 AM, Anders Thoresson [EMAIL PROTECTED] wrote: Hi, I'm trying to write a function that validates the input in a textarea. I just want to allow alphanumrical characters, and if the user enters anything else, I display an error message by calling error(). But the following doesn't work. Even if I enter hello in the textarea, I get the error message. What am I missing? // validate entered text in textarea function validate_textarea($unchecked_text) { if (!preg_match (/^[a-zåäö0-9]$/is, $unchecked_text)) { error(You have used unlegal characters, just alphanumeric is ok.); } } Best regards, Anders -- Tracy F. Rotton [EMAIL PROTECTED] http://www.taupecat.com/ ... I like the 49ers because they're pure of heart, Seattle because they've got something to prove, and the Raiders because they always cheat. -- Lisa Simpson, Lisa the Greek -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php