Re: [PHP] Regex

2012-07-27 Thread Sebastian Krebs

Am 27.07.2012 19:54, schrieb shiplu:

#[0-9a-zA-Z,\.]#




You should escape out that period as it will match any character otherwise.
Thanks,
Ash



Ash, Thats not true. In character class only meta-characters are \ ^ - [


And the dash only when it's not the first, or the last in the class.


and ]. This is the rule of PCRE (see
http://www.pcre.org/pcre.txt).
I assume we are talking about pcre as everybody used delimiter here which
is required in pcre.




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



Re: [PHP] Regex

2012-07-27 Thread shiplu
>#[0-9a-zA-Z,\.]#
> >
>
> You should escape out that period as it will match any character otherwise.
> Thanks,
> Ash
>

Ash, Thats not true. In character class only meta-characters are \ ^ - [
and ]. This is the rule of PCRE (see
http://www.pcre.org/pcre.txt).
I assume we are talking about pcre as everybody used delimiter here which
is required in pcre.

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] Regex

2012-07-27 Thread David Harkness
On Fri, Jul 27, 2012 at 10:16 AM, Ashley Sheridan
wrote:

> "Simon Dániel"  wrote:
>
> >#[0-9a-zA-Z,\.]#
>
> You should escape out that period as it will match any character otherwise
>

The dot only matches a period inside a character class [...].

David


Re: [PHP] Regex

2012-07-27 Thread Ashley Sheridan


"Simon Dániel"  wrote:

>#[0-9a-zA-Z,\.]#
>

You should escape out that period as it will match any character otherwise.
Thanks,
Ash
http://ashleysheridan.co.uk

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



Re: [PHP] Regex

2012-07-27 Thread Sebastian Krebs

Hi,

Am 27.07.2012 19:07, schrieb Ethan Rosenberg:

Dear list -

I've tried everything  and am still stuck.

A regex that will accept numbers, letters, comma, period and no other
characters


This?

/^[0-9a-zA-Z,.]$/

Regards,
Sebastian




Thanks.

Ethan Rosenberg






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



Re: [PHP] Regex

2012-07-27 Thread Stuart Dallas
On 27 Jul 2012, at 18:07, Ethan Rosenberg  wrote:

> I've tried everything  and am still stuck.
> 
> A regex that will accept numbers, letters, comma, period and no other 
> characters

/^[0-9a-zA-Z,\.]+$/

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

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



Re: [PHP] Regex

2012-07-27 Thread Simon Dániel
#[0-9a-zA-Z,.]#

2012/7/27 Ethan Rosenberg 

> Dear list -
>
> I've tried everything  and am still stuck.
>
> A regex that will accept numbers, letters, comma, period and no other
> characters
>
> Thanks.
>
> Ethan Rosenberg
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] regex or 'tidy' script to fix broken

2011-08-10 Thread Camilo Sperberg

On 10-08-2011, at 16:54, Daevid Vincent wrote:

>> -Original Message-
>> From: Camilo Sperberg [mailto:unrea...@gmail.com]
>> Sent: Tuesday, August 09, 2011 5:27 PM
>> 
>> For the first one, it may be that zend studio does have an internal script
>> to do the job. Check the general preferences tab, template stuff. 
> 
> Nope. Nothing there. Those templates are for when you create new blurbs of
> code, not modifying existing code.
> 
> There is a formatter however, sadly it doesn't have an option to force these
> (you'd think that would be the perfect place to do this too huh.) In fact, I
> posted this here:
> 
> http://forums.zend.com/viewtopic.php?f=59&t=19173#p59348

That is sad to hear, I have never done the same thing you are now, but I 
thought it could help.

> 
> Many people mistakenly think that short version is going to be deprecated
> away. It is not. The PHP Devs have already clarified only the " is, not this one.
> 
> http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
> 

I had no idea, I thought short tags also implied short if-else, short echo and 
so on, good to know that, thanks for the clarification ;)

> 
>> Second question: zend studio displays all variables used by a script by
>> clicking the arrow next to te file name. 
> 
> I've used ZS for 4+ years now, and comicaly have never even used those
> little down arrows next to a file. HAHAH! Good to know. Although it is a
> little strange as they seem to only be where you use a "=" assignment. It
> doesn't know about "->" or other instances of that variable (like if you
> echo it or something). But still could prove useful.

Eclipse/Zend Studio is so full of options that you can miss a lot of them. 
Another downside of the little arrow thing is that it doesn't recognize arrays, 
which is obvious because arrays can only be read on runtime, well, same thing 
as objects.

> 
>> If you want to display it in runtime, you can: print_r($GLOBALS);
> 
> Whoa nelly! That prints out WAAY too much information ;-)
> 
> But thanks. Not sure why I didn't think of that one. Maybe because at one
> time I did use it, got sensory overload from the amount of data it spews to
> the page, and then blocked it out of my mind for future use. :)

Yeah I know it displays a lot of information, but I use it sometimes and it's 
the only way I know to display all variables, arrays and stuff in a neat and 
nice way. You can also install xDebug and use the included debugger in ZS, but 
sometimes using a simple print_r is faster.

Greetings :)

___
Mi blog
CHW
Mi Twitter


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



RE: [PHP] regex or 'tidy' script to fix broken

2011-08-10 Thread Daevid Vincent
> -Original Message-
> From: Camilo Sperberg [mailto:unrea...@gmail.com]
> Sent: Tuesday, August 09, 2011 5:27 PM
> 
> For the first one, it may be that zend studio does have an internal script
> to do the job. Check the general preferences tab, template stuff. 

Nope. Nothing there. Those templates are for when you create new blurbs of
code, not modifying existing code.

There is a formatter however, sadly it doesn't have an option to force these
(you'd think that would be the perfect place to do this too huh.) In fact, I
posted this here:

http://forums.zend.com/viewtopic.php?f=59&t=19173#p59348

> Please note that  version. It's
shorter, cleaner and easier to read.

Many people mistakenly think that short version is going to be deprecated
away. It is not. The PHP Devs have already clarified only the "http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

> Also the short if version "1 == 1 ? True : false" should be replaced if
i'm correct.

You are not. ;-)

The Ternary operator statement would never go away. It is a standard
comparison operator in pretty much any language and would be completely
stupid of the PHP Devs to deviate that far from the norm.

http://php.net/manual/en/language.operators.comparison.php

Plus I love that operator and use it quite frequently. However, I use it
like this just for clarity:

echo "your result is ".((1 == 1) ? 'true' : 'false').'';

> Second question: zend studio displays all variables used by a script by
> clicking the arrow next to te file name. 

I've used ZS for 4+ years now, and comicaly have never even used those
little down arrows next to a file. HAHAH! Good to know. Although it is a
little strange as they seem to only be where you use a "=" assignment. It
doesn't know about "->" or other instances of that variable (like if you
echo it or something). But still could prove useful.

> If you want to display it in runtime, you can: print_r($GLOBALS);

Whoa nelly! That prints out WAAY too much information ;-)

But thanks. Not sure why I didn't think of that one. Maybe because at one
time I did use it, got sensory overload from the amount of data it spews to
the page, and then blocked it out of my mind for future use. :)


ÐÆ5ÏÐ
There are only 11 types of people in this world. Those that think binary
jokes are funny, those that don't, and those that don't know binary.
--

> Sent from my iPhone 5 Beta [Confidential use only]
> 
> On 09-08-2011, at 19:40, "Daevid Vincent"  wrote:
> 
> > I've inherited a bunch of code and the previous developers have done two
> > things that are really bugging me and I want to clean up.
> >
> > [a] They use short-tag " > search/replace style Regex (ideally for ZendStudio/Eclipse) that will
run
> > through all the files in the project and fix those? There are lots of
> cases
> > to account for such as a space after the ? or nospace or a newline or
even
> > other text (which are all valid cases).
> >
> > [b] The other thing they do use use register_globals in the php.ini
file.
> Is
> > there a good way to see all the variables that a page uses? Something I
> can
> > print at the bottom of the page on my dev box - ideally with enough
> > introspection to know where that variable originated from, and then I
can
> > start converting things to $_GET, $_POST,  $_SESSION, $_COOKIE, etc.
> >


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



Re: [PHP] regex or 'tidy' script to fix broken

2011-08-09 Thread Camilo Sperberg
For the first one, it may be that zend studio does have an internal script to 
do the job. Check the general preferences tab, template stuff. Please note that 
 wrote:

> I've inherited a bunch of code and the previous developers have done two
> things that are really bugging me and I want to clean up.
> 
> [a] They use short-tag " search/replace style Regex (ideally for ZendStudio/Eclipse) that will run
> through all the files in the project and fix those? There are lots of cases
> to account for such as a space after the ? or nospace or a newline or even
> other text (which are all valid cases).
> 
> [b] The other thing they do use use register_globals in the php.ini file. Is
> there a good way to see all the variables that a page uses? Something I can
> print at the bottom of the page on my dev box - ideally with enough
> introspection to know where that variable originated from, and then I can
> start converting things to $_GET, $_POST,  $_SESSION, $_COOKIE, etc.
> 

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



Re: [PHP] Regex pattern for preg_match_all

2011-02-22 Thread Yann Milin

Le 19/02/2011 0:23, Tommy Pham a écrit :

@Simon,

Thanks for explaining about the [^href].  I need to read up more about
greediness.  I thought I understood it but guess not.

@Peter,

I tried your pattern but it didn't capture all of my new test cases.
Also, it captures the single/double quotes in addition to the
fragments inside the href.  I couldn't figure out how to modify your
pattern to exclude the ', ", and URL fragment from group 1 matches.

Below is the new pattern with the new sample test cases that I got it
to work.  The new pattern failed only 1 of the non-compliant.

$html =<Images
http://video.search.yahoo.com/video";
data-b="http://www.yahoo.com";>Video
http://local.yahoo.com/results";
data-b="http://www.yahoo.com";>Local
http://shopping.yahoo.com/search";
data-b="http://www.yahoo.com";>Shopping
http://tools.search.yahoo.com/about/forsearchers.html";>More
HTML;

$pattern = 
'%]*?href\s*=\s*["\']?([^"\'#>]*)["\']?\s?[^>]*>(.*?)%ims';

preg_match_all($pattern, $html, $matches);

Thanks for your time,
Tommy


Hi Tommy,

This is why you shouldn't mix regexes and HTML/XML, especially when you 
are not sure that you are working with valid/consistent html.
A great/fun answer has been posted on StackOverflow about this at 
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454


You could easily break any regular expressions solution by adding some 
valid comments, see example here : 
http://stackoverflow.com/questions/1357357/regexp-to-add-attribute-in-any-xml-tags/1357393#1357393


You really should consider using a XML parser instead for this kind of job.

Here is a simple sample that matches your example :

$html = $oTidy->repairString($html,array("clean" => true, 
"drop-proprietary-attributes" => true));

unset($oTidy);

$matches = get_links($html);

function get_links($html) {

// Create a new DOM Document to hold our webpage structure
$xml = new DOMDocument();

// Load the url's contents into the DOM
$xml->loadHTML($html);

// Empty array to hold all links to return
$links = array();

//Loop through each  tag in the dom and add it to the link array
foreach($xml->getElementsByTagName('a') as $link) {
$links[] = array('url' => $link->getAttribute('href'), 'text' 
=> $link->nodeValue);

}

//Return the links
return $links;
}
?>

Regards,
Yann

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



Re: [PHP] Regex pattern for preg_match_all

2011-02-18 Thread Tommy Pham
@Simon,

Thanks for explaining about the [^href].  I need to read up more about
greediness.  I thought I understood it but guess not.

@Peter,

I tried your pattern but it didn't capture all of my new test cases.
Also, it captures the single/double quotes in addition to the
fragments inside the href.  I couldn't figure out how to modify your
pattern to exclude the ', ", and URL fragment from group 1 matches.

Below is the new pattern with the new sample test cases that I got it
to work.  The new pattern failed only 1 of the non-compliant.

$html = <Images
http://video.search.yahoo.com/video";
data-b="http://www.yahoo.com";>Video
http://local.yahoo.com/results";
data-b="http://www.yahoo.com";>Local
http://shopping.yahoo.com/search";
data-b="http://www.yahoo.com";>Shopping
http://tools.search.yahoo.com/about/forsearchers.html"; >More
HTML;

$pattern = 
'%]*?href\s*=\s*["\']?([^"\'#>]*)["\']?\s?[^>]*>(.*?)%ims';

preg_match_all($pattern, $html, $matches);

Thanks for your time,
Tommy

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



Re: [PHP] Regex pattern for preg_match_all

2011-02-18 Thread Peter Lind
On 18 February 2011 22:36, Tommy Pham  wrote:
> Hi folks,
>
> This is not directly relating to PHP but it's Friday so I'm gonna give
> it a shot :).  Would someone please help me figure out why my regex
> pattern doesn't work.  Below is the code and sample data:
>
> $html = <<  href="http://images.search.yahoo.com/images";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Images
>  href="http://video.search.yahoo.com/video";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Video
>  href="http://local.yahoo.com/results";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Local
>  href="http://shopping.yahoo.com/search";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Shopping
>  href="http://tools.search.yahoo.com/about/forsearchers.html"; > class="tab-cover y-mast-bg-hide">More class="y-fp-pg-controls arrow">
> HTML;
>
> $pattern = 
> '%]*>(.*)?%im';
> preg_match_all($pattern, $html, $matches);
>
> The only matches I got is:
>
> Match 1 of 1:    href="http://local.yahoo.com/results";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Local
>
> Group 1:        http://local.yahoo.com/results
>
> Group 2:         style="padding-left:0em;padding-right:0em;">Local
>
> The pattern I made was to work in cases where the page is
> non-compliant to any of standard W3.
>

Not entirely sure what your input data is, as I'm guessing one or more
mail programs may have added line breaks. When I run the code I get no
matches at all - so I'm guessing you might have different input on
your end. More specifically, I'm also guessing you have line breaks on
your end, but not equally distributed - which would explain the one
hit.
 Apart from that, there are a couple of things I'd rework in your regex:

%]*>(.*?)%ims

* added modifier to whitespace at first
* allowing for any character not followed by href (non-greedy)
* match the href
* use proper alternation
* capture anything inside the  tag, non-greedy
* match with a closing  tag

Results:
array(3) {
  [0]=>
  array(5) {
[0]=>
string(205) "http://images.search.yahoo.com/images";
data-b="http://www.yahoo.com";>Images"
[1]=>
string(201) "http://video.search.yahoo.com/video";
data-b="http://www.yahoo.com";>Video"
[2]=>
string(196) "http://local.yahoo.com/results";
data-b="http://www.yahoo.com";>Local"
[3]=>
string(204) "http://shopping.yahoo.com/search";
data-b="http://www.yahoo.com";>Shopping"
[4]=>
string(188) "http://tools.search.yahoo.com/about/forsearchers.html"; >More"
  }
  [1]=>
  array(5) {
[0]=>
string(39) ""http://images.search.yahoo.com/images"";
[1]=>
string(37) ""http://video.search.yahoo.com/video"";
[2]=>
string(32) ""http://local.yahoo.com/results"";
[3]=>
string(34) ""http://shopping.yahoo.com/search"";
[4]=>
string(55) ""http://tools.search.yahoo.com/about/forsearchers.html"";
  }
  [2]=>
  array(5) {
[0]=>
string(96) "Images"
[1]=>
string(95) "Video"
[2]=>
string(95) "Local"
[3]=>
string(98) "Shopping"
[4]=>
string(94) "More"
  }


-- 

WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15


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



Re: [PHP] Regex pattern for preg_match_all

2011-02-18 Thread Simon J Welsh
As far as I can tell, your problem lies in [^href]*. That will match any 
characters other than h, r, e or f, not anything other than the string href. 
Consider replacing it with [^>]*?. The ? makes it non-greedy so it will stop as 
soon as it can (when it matches the first href) rather than as late as it can 
(when it matches a >)
---
Simon Welsh
Sent from my phone, excuse the brevity

On 19/02/2011, at 10:36, Tommy Pham  wrote:

> Hi folks,
> 
> This is not directly relating to PHP but it's Friday so I'm gonna give
> it a shot :).  Would someone please help me figure out why my regex
> pattern doesn't work.  Below is the code and sample data:
> 
> $html = <<  href="http://images.search.yahoo.com/images";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Images
>  href="http://video.search.yahoo.com/video";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Video
>  href="http://local.yahoo.com/results";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Local
>  href="http://shopping.yahoo.com/search";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Shopping
>  href="http://tools.search.yahoo.com/about/forsearchers.html"; > class="tab-cover y-mast-bg-hide">More class="y-fp-pg-controls arrow">
> HTML;
> 
> $pattern = 
> '%]*>(.*)?%im';
> preg_match_all($pattern, $html, $matches);
> 
> The only matches I got is:
> 
> Match 1 of 1: href="http://local.yahoo.com/results";
> data-b="http://www.yahoo.com";> style="padding-left:0em;padding-right:0em;">Local
> 
> Group 1:http://local.yahoo.com/results
> 
> Group 2: style="padding-left:0em;padding-right:0em;">Local
> 
> The pattern I made was to work in cases where the page is
> non-compliant to any of standard W3.
> 
> Thanks,
> Tommy
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


Re: [PHP] Regex for ... genealogical names

2011-01-01 Thread Ashley Sheridan
On Sat, 2011-01-01 at 09:46 +, Lester Caine wrote:

> A slightly more complex problem than phone numbers ...
> 
> It is a sort of convention to use the format 'JohnDoeSMITH' or 'John Doe 
> SMITH' 
> where each forename starts with a capital and the surname is in upper case. I 
> have a crude method of scanning for the capitals and splitting this to give 
> me 
> an array of name segments with [0] as the Surname and a variable number of 
> Forenames, but is there an 'elegant' way via regex to extract this into an 
> array?
> 
> -- 
> Lester Caine - G8HFL
> -
> Contact - http://lsces.co.uk/wiki/?page=contact
> L.S.Caine Electronic Services - http://lsces.co.uk
> EnquirySolve - http://enquirysolve.com/
> Model Engineers Digital Workshop - http://medw.co.uk//
> Firebird - http://www.firebirdsql.org/index.php
> 


I wouldn't try and do this with a regex, it would just become too
complicated. What about people with no middle name, or multiple middle
names? How do you deal with double-barrelled names like John
Walter-Smythe Doe? You would be far better off using multiple input
boxes for this sort of thing, and then format it as required when
outputting the data.

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




Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel P. Brown
On Fri, Dec 31, 2010 at 19:09, Jim Lucas  wrote:
>
> Actually...
>
> Specified here [1] it says that the {1,} is the same as '+'.  I think you 
> should
> drop the comma.  If you don't this would be valid 844-2345-123456
>
> ^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$
>
> should be
>
> ^[2-9]{1}[0-9]{2}\-[2-9]{1}[0-9]{2}\-[0-9]{4}$

Bah, you're absolutely correct.  Force of habit with the commas.
I didn't even notice the sample test cases I put into that test array
didn't check for more than the number of digits per field, either.
Good catch, Jim, and Happy New Year.

-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Jim Lucas
On 12/29/2010 4:35 PM, Daniel P. Brown wrote:
> On Wed, Dec 29, 2010 at 19:12, Ethan Rosenberg  wrote:
>> Dear List -
>>
>> Thank you for all your help in the past.
>>
>> Here is another one
>>
>> I would like to have a regex  which would validate that a telephone number
>> is in the format xxx-xxx-.
> 
> Congrats.  People in Hell would like ice water.  Now we all know
> that everyone wants something.  ;-P
> 
> Really, this isn't a PHP question, but rather one of regular
> expressions.  That said, something like this (untested) should work:
> 
>  
> $numbers = array(
> '123-456-7890',
> '2-654-06547',
> 'sf34-asdf-',
> 'abc-def-ghij',
> '555_555_',
> '000-000-',
> '8007396325',
> '241-555-2091',
> '800-555-0129',
> '900-976-739',
> '5352-342=452',
> '200-200-2000',
> );
> 
> foreach ($numbers as $n) {
> echo $n.(validate_phone($n) ? ' is ' : ' is not ').'a valid
> US/Canadian telephone number.'.PHP_EOL;
> }
> 
> 
> function validate_phone($number) {
> 
> if 
> (preg_match('/^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$/',trim($number)))
> {
> return true;
> }
> 
> return false;
> }
> ?>
> 
> 

Actually...

Specified here [1] it says that the {1,} is the same as '+'.  I think you should
drop the comma.  If you don't this would be valid 844-2345-123456

^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$

should be

^[2-9]{1}[0-9]{2}\-[2-9]{1}[0-9]{2}\-[0-9]{4}$


1  http://us.php.net/manual/en/regexp.reference.repetition.php

Jim Lucas

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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Steve Staples
On Wed, 2010-12-29 at 19:35 -0500, Daniel P. Brown wrote:
> On Wed, Dec 29, 2010 at 19:12, Ethan Rosenberg  wrote:
> > Dear List -
> >
> > Thank you for all your help in the past.
> >
> > Here is another one
> >
> > I would like to have a regex  which would validate that a telephone number
> > is in the format xxx-xxx-.
> 
> Congrats.  People in Hell would like ice water.  Now we all know
> that everyone wants something.  ;-P
> 
> Really, this isn't a PHP question, but rather one of regular
> expressions.  That said, something like this (untested) should work:
> 
>  
> $numbers = array(
> '123-456-7890',
> '2-654-06547',
> 'sf34-asdf-',
> 'abc-def-ghij',
> '555_555_',
> '000-000-',
> '8007396325',
> '241-555-2091',
> '800-555-0129',
> '900-976-739',
> '5352-342=452',
> '200-200-2000',
> );
> 
> foreach ($numbers as $n) {
> echo $n.(validate_phone($n) ? ' is ' : ' is not ').'a valid
> US/Canadian telephone number.'.PHP_EOL;
> }
> 
> 
> function validate_phone($number) {
> 
> if 
> (preg_match('/^[2-9]{1,}[0-9]{2,}\-[2-9]{1,}[0-9]{2,}\-[0-9]{4,}$/',trim($number)))
> {
> return true;
> }
> 
> return false;
> }
> ?>
> 
 THIS 
is the regex you want to use... it is the most complete one that has
been posted here, and it works.


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel Brown
On Fri, Dec 31, 2010 at 12:05, Dmitriy Ugnichenko
 wrote:
> I guess, this will work fine
>
> ereg('[0-9]{3}-[0-9]{3}-[0-9]{4}',  $phone_number);

Not quite.  Plus, all ereg* functions have been deprecated for
some time now.

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Dmitriy Ugnichenko
I guess, this will work fine

ereg('[0-9]{3}-[0-9]{3}-[0-9]{4}',  $phone_number);

On Thu, Dec 30, 2010 at 2:12 AM, Ethan Rosenberg wrote:

> Dear List -
>
> Thank you for all your help in the past.
>
> Here is another one
>
> I would like to have a regex  which would validate that a telephone number
> is in the format xxx-xxx-.
>
> Thanks.
>
> Ethan
>
> MySQL 5.1  PHP 5  Linux [Debian (sid)]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
with best regards,
Dmitriy.


Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Daniel P. Brown
On Fri, Dec 31, 2010 at 11:04, Per Jessen  wrote:
>
> AFAIK, they too vary from country to country.  Swiss mobile numbers are
> 07[6789] NNN, the latter usually written as NNN NN NN, but also
> often in a way that will help remembering the number.
> Danish mobile#s are the same as land line numbers, no area code, just
> .

In the US and Canada, though, there's [as of yet] no difference
between landline, mobile, VOIP, fax, toll-free, premium (900), et
cetera.  Again, that's why I wrote out the example the way I did,
which conforms to NANP (NPA/NXX) standards.  It's the only suggestion
so far that will work completely (which sounds cocky, but screw it,
it's the last Friday of the year  ;-P).

-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Per Jessen
a...@ashleysheridan.co.uk wrote:

> Sorry for top-post, on phone.
> 
> What about mobile phone numbers (cell phones you call them in the US)
> do they conform to the same format? 

AFAIK, they too vary from country to country.  Swiss mobile numbers are
07[6789] NNN, the latter usually written as NNN NN NN, but also
often in a way that will help remembering the number.  
Danish mobile#s are the same as land line numbers, no area code, just
. 



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


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Nathan Rixham

Ethan Rosenberg wrote:

At 07:11 AM 12/31/2010, Nathan Rixham wrote:

Ethan Rosenberg wrote:
FYI [to all the list] -- I thank all for their input.  I only needed 
US phones, and I am forcing the user of the form to conform to 
xxx-xxx- as the input format.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then format 
how you like to save, thus giving users a looser, more friendly, 
experience.

+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone number. 
At subsequent visits, the patient will be referenced by his/hers medical 
record number.  If the patient either forgot their clinic card, or 
cannot remember their medical record number, a search will be 
performed.  One of the many parameters that can be used in the search is 
the phone number. It is easier if all the data has a fixed format.  The 
form for  the initial visit will use a regex that will validate the 
phone number. As  the research will be performed in the US, only US 
numbers have to be validated.


Ethan,

I think you misunderstand, I'm saying that regardless of which format 
you use within the system, users could enter phone numbers as 
"1231231234" "123 123 1234" "123-123 1234" or any variant they like, 
that's completely orthogonal to how you validate and save the data, in 
all of those cases all you need to do string non-numeric chars to 
validate, you may also find your indexes work that bit quicker storing 
numbers rather than specially (and needlessly) formatted string.


Likewise on the way back out, when presenting the numbers to users, all 
you need to do is string format them.


Follow?


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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Ethan Rosenberg

At 09:27 AM 12/31/2010, a...@ashleysheridan.co.uk wrote:

Sorry for top-post, on phone.

What about mobile phone numbers (cell phones you call them in the 
US) do they conform to the same format? I know there have been times 
myself when I've been without a landline number leaving me with only 
my mobile as a means of contact.


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

- Reply message -
From: "Ethan Rosenberg" 
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: "Nathan Rixham" 
Cc: "php-general@lists.php.net" 


At 07:11 AM 12/31/2010, Nathan Rixham wrote:
>Ethan Rosenberg wrote:
>>FYI [to all the list] -- I thank all for their input.  I only
>>needed US phones, and I am forcing the user of the form to conform
>>to xxx-xxx- as the input format.
>
>out of interest, why are you forcing you're users to conform to that
>input format? you could simply strip all non-numeric chars then
>format how you like to save, thus giving users a looser, more
>friendly, experience.
+
Nathan -

This expression will be used to search a database which will contain
patient data resulting from medical research.  At the initial visit a
medical record number will be assigned to the patient.  Other
information will be collected at that point; eg,  the telephone
number. At subsequent visits, the patient will be referenced by
his/hers medical record number.  If the patient either forgot their
clinic card, or cannot remember their medical record number, a search
will be performed.  One of the many parameters that can be used in
the search is the phone number. It is easier if all the data has a
fixed format.  The form for  the initial visit will use a regex that
will validate the phone number. As  the research will be performed in
the US, only US numbers have to be validated.

Hope this helps.

Ethan




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





Ash -

In contrast to some non-US phone numbers, all the numbers here [cell 
and landline] have the same format.


Ethan 




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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread a...@ashleysheridan.co.uk
Sorry for top-post, on phone.

What about mobile phone numbers (cell phones you call them in the US) do they 
conform to the same format? I know there have been times myself when I've been 
without a landline number leaving me with only my mobile as a means of contact.

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

- Reply message -
From: "Ethan Rosenberg" 
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: "Nathan Rixham" 
Cc: "php-general@lists.php.net" 


At 07:11 AM 12/31/2010, Nathan Rixham wrote:
>Ethan Rosenberg wrote:
>>FYI [to all the list] -- I thank all for their input.  I only 
>>needed US phones, and I am forcing the user of the form to conform 
>>to xxx-xxx- as the input format.
>
>out of interest, why are you forcing you're users to conform to that 
>input format? you could simply strip all non-numeric chars then 
>format how you like to save, thus giving users a looser, more 
>friendly, experience.
+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone 
number. At subsequent visits, the patient will be referenced by 
his/hers medical record number.  If the patient either forgot their 
clinic card, or cannot remember their medical record number, a search 
will be performed.  One of the many parameters that can be used in 
the search is the phone number. It is easier if all the data has a 
fixed format.  The form for  the initial visit will use a regex that 
will validate the phone number. As  the research will be performed in 
the US, only US numbers have to be validated.

Hope this helps.

Ethan




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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Ethan Rosenberg

At 07:11 AM 12/31/2010, Nathan Rixham wrote:

Ethan Rosenberg wrote:
FYI [to all the list] -- I thank all for their input.  I only 
needed US phones, and I am forcing the user of the form to conform 
to xxx-xxx- as the input format.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then 
format how you like to save, thus giving users a looser, more 
friendly, experience.

+
Nathan -

This expression will be used to search a database which will contain 
patient data resulting from medical research.  At the initial visit a 
medical record number will be assigned to the patient.  Other 
information will be collected at that point; eg,  the telephone 
number. At subsequent visits, the patient will be referenced by 
his/hers medical record number.  If the patient either forgot their 
clinic card, or cannot remember their medical record number, a search 
will be performed.  One of the many parameters that can be used in 
the search is the phone number. It is easier if all the data has a 
fixed format.  The form for  the initial visit will use a regex that 
will validate the phone number. As  the research will be performed in 
the US, only US numbers have to be validated.


Hope this helps.

Ethan




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



Re: [PHP] Regex for telephone numbers

2010-12-31 Thread Nathan Rixham

Ethan Rosenberg wrote:
FYI [to all the list] -- I thank all for their input.  I only needed US 
phones, and I am forcing the user of the form to conform to xxx-xxx- 
as the input format.


out of interest, why are you forcing you're users to conform to that 
input format? you could simply strip all non-numeric chars then format 
how you like to save, thus giving users a looser, more friendly, experience.


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



Re: [PHP] Regex for telephone numbers

2010-12-30 Thread Tamara Temple


On Dec 29, 2010, at 6:12 PM, Ethan Rosenberg wrote:

I would like to have a regex  which would validate that a telephone  
number is in the format xxx-xxx-.




http://lmgtfy.com/?q=regex+to+validate+US+phone+numbers

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



[PHP] Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-30 Thread Daniel Brown
On Thu, Dec 30, 2010 at 14:07, Ethan Rosenberg  wrote:
>
> Josh -
>
> I used use \d{3}-\d{3}-\d{4}.
>
> It works beautifully!!

Just keep in mind that invalid numbers will also pass that check,
such as 000-000- or 123-456-6789.  That's why my example was a bit
more involved.

-- 

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

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



Re: [PHP] Regex for telephone numbers

2010-12-30 Thread Ethan Rosenberg

At 07:27 PM 12/29/2010, Josh Kehn wrote:



On Dec 29, 2010, at 7:12 PM, Ethan Rosenberg  wrote:

> Dear List -
>
> Thank you for all your help in the past.
>
> Here is another one
>
> I would like to have a regex  which would validate that a 
telephone number is in the format xxx-xxx-.

>
> Thanks.
>
> Ethan
>
> MySQL 5.1  PHP 5  Linux [Debian (sid)]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

You can't, phone numbers are more complex then that. You could use 
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.


Regards,

-Josh
___
http://joshuakehn.com






Sent from my iPod

Josh -

I used use \d{3}-\d{3}-\d{4}.

It works beautifully!!

FYI [to all the list] -- I thank all for their input.  I only needed 
US phones, and I am forcing the user of the form to conform to 
xxx-xxx- as the input format.


Ethan




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



Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Daniel P. Brown
On Wed, Dec 29, 2010 at 19:12, Ethan Rosenberg  wrote:
> Dear List -
>
> Thank you for all your help in the past.
>
> Here is another one
>
> I would like to have a regex  which would validate that a telephone number
> is in the format xxx-xxx-.

Congrats.  People in Hell would like ice water.  Now we all know
that everyone wants something.  ;-P

Really, this isn't a PHP question, but rather one of regular
expressions.  That said, something like this (untested) should work:




-- 

Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

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



Re: [PHP] Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Alexis
Why not have three separate fields for each part, as that way you don't 
need to bother about how the user separates them, as trust me, if they 
can break it, they will.
I have found it is best to always limit the amount of free entry you 
permit a user, as that will drastically cut back in data entry validation.


Alexis


On 29/12/10 17:46, Karl DeSaulniers wrote:

Hi Ethan,
Could you do a string compare and check at certain characters for a dash?
IE:
check the second character to see if it is a dash for 1-800...
if that is not a dash, check the fourth character for a dash, 469-9...
then the other places where dashes would be based on those two characters.
You may have to investigate how international numbers would work and
adjust appropriately, but for the US, that should work.
Then just send an error message when it isn't like you want.
JAT

Karl


On Dec 29, 2010, at 6:27 PM, Josh Kehn wrote:




On Dec 29, 2010, at 7:12 PM, Ethan Rosenberg 
wrote:


Dear List -

Thank you for all your help in the past.

Here is another one

I would like to have a regex which would validate that a telephone
number is in the format xxx-xxx-.

Thanks.

Ethan

MySQL 5.1 PHP 5 Linux [Debian (sid)]


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



You can't, phone numbers are more complex then that. You could use
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.

Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com




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



[PHP] Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Karl DeSaulniers

You could also help them out a little with something like..

$phone = str_replace("(", "", $phone);
$phone = str_replace(")", "-", $phone);

HTH,

Karl


On Dec 29, 2010, at 6:27 PM, Josh Kehn wrote:




On Dec 29, 2010, at 7:12 PM, Ethan Rosenberg   
wrote:



Dear List -

Thank you for all your help in the past.

Here is another one

I would like to have a regex  which would validate that a  
telephone number is in the format xxx-xxx-.


Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)]


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



You can't, phone numbers are more complex then that. You could use  
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.


Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com


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



[PHP] Re: [PHP-DB] Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Karl DeSaulniers

Hi Ethan,
Could you do a string compare and check at certain characters for a  
dash?

IE:
check the second character to see if it is a dash for 1-800...
if that is not a dash, check the fourth character for a dash, 469-9...
then the other places  where dashes would be based on those two  
characters.
You may have to investigate how international numbers would work and  
adjust appropriately, but for the US, that should work.

Then just send an error message when it isn't like you want.
JAT

Karl


On Dec 29, 2010, at 6:27 PM, Josh Kehn wrote:




On Dec 29, 2010, at 7:12 PM, Ethan Rosenberg   
wrote:



Dear List -

Thank you for all your help in the past.

Here is another one

I would like to have a regex  which would validate that a  
telephone number is in the format xxx-xxx-.


Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)]


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



You can't, phone numbers are more complex then that. You could use  
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.


Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Karl DeSaulniers
Design Drumm
http://designdrumm.com


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



Re: [PHP] Regex for telephone numbers

2010-12-29 Thread Josh Kehn


On Dec 29, 2010, at 7:12 PM, Ethan Rosenberg  wrote:

> Dear List -
> 
> Thank you for all your help in the past.
> 
> Here is another one
> 
> I would like to have a regex  which would validate that a telephone number is 
> in the format xxx-xxx-.
> 
> Thanks.
> 
> Ethan
> 
> MySQL 5.1  PHP 5  Linux [Debian (sid)] 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

You can't, phone numbers are more complex then that. You could use 
\d{3}-\d{3}-\d{4} to match that basic pattern for all numbers though.

Regards,

-Josh
___
http://joshuakehn.com
Sent from my iPod
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Regex for telephone numbers

2010-12-29 Thread admin
Also remove your stupid Email filter.
If you need a email filter, you should not be on this list or learn to setup
rules one.


Richard L. Buskirk


-Original Message-
From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: Wednesday, December 29, 2010 7:12 PM
To: php-db-lists.php.net; php-general@lists.php.net
Subject: [PHP] Regex for telephone numbers

Dear List -

Thank you for all your help in the past.

Here is another one

I would like to have a regex  which would validate that a telephone 
number is in the format xxx-xxx-.

Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)] 



-- 
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] Regex for telephone numbers

2010-12-29 Thread Simon J Welsh
On 30/12/2010, at 1:12 PM, Ethan Rosenberg wrote:

> Dear List -
> 
> Thank you for all your help in the past.
> 
> Here is another one
> 
> I would like to have a regex  which would validate that a telephone number is 
> in the format xxx-xxx-.
> 
> Thanks.
> 
> Ethan
> 
> MySQL 5.1  PHP 5  Linux [Debian (sid)] 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

\d{3}-\d{3}-\d{4}

Also, have a look at the phoneNumber method in the relevant Validate PEAR 
package: http://pear.php.net/packages.php?catpid=50&catname=Validate

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e


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



RE: [PHP] Regex for telephone numbers

2010-12-29 Thread admin
I suggest you try javascript.



Richard L. Buskirk

-Original Message-
From: Ethan Rosenberg [mailto:eth...@earthlink.net] 
Sent: Wednesday, December 29, 2010 7:12 PM
To: php-db-lists.php.net; php-general@lists.php.net
Subject: [PHP] Regex for telephone numbers

Dear List -

Thank you for all your help in the past.

Here is another one

I would like to have a regex  which would validate that a telephone 
number is in the format xxx-xxx-.

Thanks.

Ethan

MySQL 5.1  PHP 5  Linux [Debian (sid)] 



-- 
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] regex pattern for extracting URLs

2009-10-23 Thread Ashley Sheridan
On Fri, 2009-10-23 at 15:17 -0400, Paul M Foster wrote:

> On Fri, Oct 23, 2009 at 01:54:40PM -0400, Brad Fuller wrote:
> 
> > Thanks Ash you are awesome!
> 
> Brad, you're violating list rules. We never say that kind of thing to
> Ash *where he can hear it*. Only behind his back. ;-}
> 
> Paul
> 
> -- 
> Paul M. Foster
> 


Well, it makes a refreshing change, off list people just want to insult
me :p

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




Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Paul M Foster
On Fri, Oct 23, 2009 at 01:54:40PM -0400, Brad Fuller wrote:

> Thanks Ash you are awesome!

Brad, you're violating list rules. We never say that kind of thing to
Ash *where he can hear it*. Only behind his back. ;-}

Paul

-- 
Paul M. Foster

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



Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Brad Fuller
On Fri, Oct 23, 2009 at 1:54 PM, Israel Ekpo  wrote:
>
>
> On Fri, Oct 23, 2009 at 1:48 PM, Ashley Sheridan 
> wrote:
>>
>> On Fri, 2009-10-23 at 13:45 -0400, Brad Fuller wrote:
>>
>> > On Fri, Oct 23, 2009 at 1:28 PM, Ashley Sheridan
>> > wrote:
>> >
>> > >  On Fri, 2009-10-23 at 13:23 -0400, Brad Fuller wrote:
>> > >
>> > > I'm looking for a regular expression to accomplish a specific task.
>> > >
>> > > I'm hoping someone who's really good at regex patterns can lend a
>> > > quick hand.
>> > >
>> > > I need a regex pattern that will grab URLs out of HTML that have a
>> > > certain link text. (i.e. the word "Continue")
>> > >
>> > > This is what I have so far but it does not work properly (If there are
>> > > other attributes in the  tag it returns them as part of the URL.)
>> > >
>> > >
>> > > preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
>> > > $html, $matches);
>> > >
>> > > It needs to be able to extract the URL and disregard arbitrary
>> > > attributes in the HTML tag
>> > >
>> > > Test it with the following examples:
>> > >
>> > > Continue
>> > > Continue
>> > > http://example.com/path/to/url.html";
>> > > class="link">Continue
>> > > http://example.com/path/to/url.html";
>> > > onlick="someFunction('foo','bar')">Continue
>> > >
>> > > Please reply
>> > >
>> > > Your help is much appreciated.
>> > >
>> > > Thanks in advance,
>> > > Brad F.
>> > >
>> > >
>> > >
>> > >
>> > > preg_match_all('#]*href\s*=\s*[\"\']+([^\"\']+?).+?>Continue#i',
>> > > $html, $matches);
>> > >
>> > > I just changed your regex a bit. What your regex was previously doing
>> > > was
>> > > matching everything from the first quote after the href= right up
>> > > until the
>> > > first > it found, which would usually be the one that closes the
>> > > opening
>> > > tag. You could make it a bit more intelligent if you wished with
>> > > backreferencing to make sure it matches against the same type of
>> > > quotation
>> > > character it matched as the start of the href's value.
>> > >
>> > >   Thanks,
>> > > Ash
>> > > http://www.ashleysheridan.co.uk
>> > >
>> > >
>> > >
>> >
>> > I appreciate the help.  However, when try this I only get the first
>> > character of the URL.  Can you double check it please.
>> >
>> > Thanks again
>>
>>
>> I think it's probably the first ? in ([^\"\']+?)
>>
>> Remove that and it should do the trick
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>
> Hi Brad,
>
> I agree with Jim.
>
> Take a look at this. It might help.
>
> 
> $xml_string = << 
>     
>     
>     
>     
>     
>     http://example.com/path/to/urlA.html";>Continue
>     http://example.com/path/to/url2.html";>Brad Fuller
>     http://example.com/path/to/urlB.html";>Continue
>     http://example.com/path/to/url4.html";>PHP.net
>     http://example.com/path/to/urlC.html";
> class="link">Continue
>      href="http://example.com/path/to/urlD.html";
> onclick="someFunction('foo','bar')">Continue
>     
>     
> 
> TEXT_BOUNDARY;
>
> $xml = simplexml_load_string($xml_string);
>
> $continue_hrefs = $xml->xpath("//a[text() = 'Continue']/@href");
>
> print_r($continue_hrefs);
>
> ?>
>

Thanks, I'm sure I will use this at some point in the future :)

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



Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Brad Fuller
On Fri, Oct 23, 2009 at 1:48 PM, Ashley Sheridan
wrote:

>  On Fri, 2009-10-23 at 13:45 -0400, Brad Fuller wrote:
>
> On Fri, Oct 23, 2009 at 1:28 PM, Ashley Sheridan
> wrote:
>
> >  On Fri, 2009-10-23 at 13:23 -0400, Brad Fuller wrote:
> >
> > I'm looking for a regular expression to accomplish a specific task.
> >
> > I'm hoping someone who's really good at regex patterns can lend a quick 
> > hand.
> >
> > I need a regex pattern that will grab URLs out of HTML that have a
> > certain link text. (i.e. the word "Continue")
> >
> > This is what I have so far but it does not work properly (If there are
> > other attributes in the  tag it returns them as part of the URL.)
> >
> > 
> > preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
> > $html, $matches);
> >
> > It needs to be able to extract the URL and disregard arbitrary
> > attributes in the HTML tag
> >
> > Test it with the following examples:
> >
> > Continue
> > Continue
> > http://example.com/path/to/url.html"; class="link">Continue
> > http://example.com/path/to/url.html";
> > onlick="someFunction('foo','bar')">Continue
> >
> > Please reply
> >
> > Your help is much appreciated.
> >
> > Thanks in advance,
> > Brad F.
> >
> >
> >
> > preg_match_all('#]*href\s*=\s*[\"\']+([^\"\']+?).+?>Continue#i',
> > $html, $matches);
> >
> > I just changed your regex a bit. What your regex was previously doing was
> > matching everything from the first quote after the href= right up until the
> > first > it found, which would usually be the one that closes the opening
> > tag. You could make it a bit more intelligent if you wished with
> > backreferencing to make sure it matches against the same type of quotation
> > character it matched as the start of the href's value.
> >
> >   Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
>
> I appreciate the help.  However, when try this I only get the first
> character of the URL.  Can you double check it please.
>
> Thanks again
>
>
> I think it's probably the first ? in ([^\"\']+?)
>
> Remove that and it should do the trick
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
That did the trick.  Thanks Ash you are awesome!

Also thanks Jim for your suggestion.  I may move to SimpleXML if the project
grows much bigger.  But for now I was looking for a nice one liner and this
is it.

Cheers,
Brad


Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Israel Ekpo
On Fri, Oct 23, 2009 at 1:48 PM, Ashley Sheridan
wrote:

> On Fri, 2009-10-23 at 13:45 -0400, Brad Fuller wrote:
>
> > On Fri, Oct 23, 2009 at 1:28 PM, Ashley Sheridan
> > wrote:
> >
> > >  On Fri, 2009-10-23 at 13:23 -0400, Brad Fuller wrote:
> > >
> > > I'm looking for a regular expression to accomplish a specific task.
> > >
> > > I'm hoping someone who's really good at regex patterns can lend a quick
> hand.
> > >
> > > I need a regex pattern that will grab URLs out of HTML that have a
> > > certain link text. (i.e. the word "Continue")
> > >
> > > This is what I have so far but it does not work properly (If there are
> > > other attributes in the  tag it returns them as part of the URL.)
> > >
> > >
> preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
> > > $html, $matches);
> > >
> > > It needs to be able to extract the URL and disregard arbitrary
> > > attributes in the HTML tag
> > >
> > > Test it with the following examples:
> > >
> > > Continue
> > > Continue
> > > http://example.com/path/to/url.html";
> class="link">Continue
> > > http://example.com/path/to/url.html";
> > > onlick="someFunction('foo','bar')">Continue
> > >
> > > Please reply
> > >
> > > Your help is much appreciated.
> > >
> > > Thanks in advance,
> > > Brad F.
> > >
> > >
> > >
> > >
> preg_match_all('#]*href\s*=\s*[\"\']+([^\"\']+?).+?>Continue#i',
> > > $html, $matches);
> > >
> > > I just changed your regex a bit. What your regex was previously doing
> was
> > > matching everything from the first quote after the href= right up until
> the
> > > first > it found, which would usually be the one that closes the
> opening
> > > tag. You could make it a bit more intelligent if you wished with
> > > backreferencing to make sure it matches against the same type of
> quotation
> > > character it matched as the start of the href's value.
> > >
> > >   Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > >
> > >
> >
> > I appreciate the help.  However, when try this I only get the first
> > character of the URL.  Can you double check it please.
> >
> > Thanks again
>
>
> I think it's probably the first ? in ([^\"\']+?)
>
> Remove that and it should do the trick
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
Hi Brad,

I agree with Jim.

Take a look at this. It might help.







http://example.com/path/to/urlA.html";>Continue
http://example.com/path/to/url2.html";>Brad Fuller
http://example.com/path/to/urlB.html";>Continue
http://example.com/path/to/url4.html";>PHP.net
http://example.com/path/to/urlC.html";
class="link">Continue
http://example.com/path/to/urlD.html";
onclick="someFunction('foo','bar')">Continue



TEXT_BOUNDARY;

$xml = simplexml_load_string($xml_string);

$continue_hrefs = $xml->xpath("//a[text() = 'Continue']/@href");

print_r($continue_hrefs);

?>

-- 
"Good Enough" is not good enough.
To give anything less than your best is to sacrifice the gift.
Quality First. Measure Twice. Cut Once.


Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Ashley Sheridan
On Fri, 2009-10-23 at 13:45 -0400, Brad Fuller wrote:

> On Fri, Oct 23, 2009 at 1:28 PM, Ashley Sheridan
> wrote:
> 
> >  On Fri, 2009-10-23 at 13:23 -0400, Brad Fuller wrote:
> >
> > I'm looking for a regular expression to accomplish a specific task.
> >
> > I'm hoping someone who's really good at regex patterns can lend a quick 
> > hand.
> >
> > I need a regex pattern that will grab URLs out of HTML that have a
> > certain link text. (i.e. the word "Continue")
> >
> > This is what I have so far but it does not work properly (If there are
> > other attributes in the  tag it returns them as part of the URL.)
> >
> > 
> > preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
> > $html, $matches);
> >
> > It needs to be able to extract the URL and disregard arbitrary
> > attributes in the HTML tag
> >
> > Test it with the following examples:
> >
> > Continue
> > Continue
> > http://example.com/path/to/url.html"; class="link">Continue
> > http://example.com/path/to/url.html";
> > onlick="someFunction('foo','bar')">Continue
> >
> > Please reply
> >
> > Your help is much appreciated.
> >
> > Thanks in advance,
> > Brad F.
> >
> >
> >
> > preg_match_all('#]*href\s*=\s*[\"\']+([^\"\']+?).+?>Continue#i',
> > $html, $matches);
> >
> > I just changed your regex a bit. What your regex was previously doing was
> > matching everything from the first quote after the href= right up until the
> > first > it found, which would usually be the one that closes the opening
> > tag. You could make it a bit more intelligent if you wished with
> > backreferencing to make sure it matches against the same type of quotation
> > character it matched as the start of the href's value.
> >
> >   Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> 
> I appreciate the help.  However, when try this I only get the first
> character of the URL.  Can you double check it please.
> 
> Thanks again


I think it's probably the first ? in ([^\"\']+?)

Remove that and it should do the trick

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




Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Brad Fuller
On Fri, Oct 23, 2009 at 1:28 PM, Ashley Sheridan
wrote:

>  On Fri, 2009-10-23 at 13:23 -0400, Brad Fuller wrote:
>
> I'm looking for a regular expression to accomplish a specific task.
>
> I'm hoping someone who's really good at regex patterns can lend a quick hand.
>
> I need a regex pattern that will grab URLs out of HTML that have a
> certain link text. (i.e. the word "Continue")
>
> This is what I have so far but it does not work properly (If there are
> other attributes in the  tag it returns them as part of the URL.)
>
> 
> preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
> $html, $matches);
>
> It needs to be able to extract the URL and disregard arbitrary
> attributes in the HTML tag
>
> Test it with the following examples:
>
> Continue
> Continue
> http://example.com/path/to/url.html"; class="link">Continue
> http://example.com/path/to/url.html";
> onlick="someFunction('foo','bar')">Continue
>
> Please reply
>
> Your help is much appreciated.
>
> Thanks in advance,
> Brad F.
>
>
>
> preg_match_all('#]*href\s*=\s*[\"\']+([^\"\']+?).+?>Continue#i',
> $html, $matches);
>
> I just changed your regex a bit. What your regex was previously doing was
> matching everything from the first quote after the href= right up until the
> first > it found, which would usually be the one that closes the opening
> tag. You could make it a bit more intelligent if you wished with
> backreferencing to make sure it matches against the same type of quotation
> character it matched as the start of the href's value.
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

I appreciate the help.  However, when try this I only get the first
character of the URL.  Can you double check it please.

Thanks again


Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Ashley Sheridan
On Fri, 2009-10-23 at 13:23 -0400, Brad Fuller wrote:

> I'm looking for a regular expression to accomplish a specific task.
> 
> I'm hoping someone who's really good at regex patterns can lend a quick hand.
> 
> I need a regex pattern that will grab URLs out of HTML that have a
> certain link text. (i.e. the word "Continue")
> 
> This is what I have so far but it does not work properly (If there are
> other attributes in the  tag it returns them as part of the URL.)
> 
> 
> preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
> $html, $matches);
> 
> It needs to be able to extract the URL and disregard arbitrary
> attributes in the HTML tag
> 
> Test it with the following examples:
> 
> Continue
> Continue
> http://example.com/path/to/url.html"; class="link">Continue
> http://example.com/path/to/url.html";
> onlick="someFunction('foo','bar')">Continue
> 
> Please reply
> 
> Your help is much appreciated.
> 
> Thanks in advance,
> Brad F.
> 


preg_match_all('#]*href\s*=\s*[\"\']+([^
\"\']+?).+?>Continue#i', $html, $matches);

I just changed your regex a bit. What your regex was previously doing
was matching everything from the first quote after the href= right up
until the first > it found, which would usually be the one that closes
the opening tag. You could make it a bit more intelligent if you wished
with backreferencing to make sure it matches against the same type of
quotation character it matched as the start of the href's value.

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




Re: [PHP] regex pattern for extracting URLs

2009-10-23 Thread Jim Lucas
Brad Fuller wrote:
> I'm looking for a regular expression to accomplish a specific task.
> 
> I'm hoping someone who's really good at regex patterns can lend a quick hand.
> 
> I need a regex pattern that will grab URLs out of HTML that have a
> certain link text. (i.e. the word "Continue")
> 
> This is what I have so far but it does not work properly (If there are
> other attributes in the  tag it returns them as part of the URL.)
> 
> 
> preg_match_all('#]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)>Continue#i',
> $html, $matches);
> 
> It needs to be able to extract the URL and disregard arbitrary
> attributes in the HTML tag
> 
> Test it with the following examples:
> 
> Continue
> Continue
> http://example.com/path/to/url.html"; class="link">Continue
> http://example.com/path/to/url.html";
> onlick="someFunction('foo','bar')">Continue
> 
> Please reply
> 
> Your help is much appreciated.
> 
> Thanks in advance,
> Brad F.
> 

Looking at this document from an XML standpoint, I could see doing this rather
easily.  Without having to use regex.  You might look into using DomDocument and
simpleXML to complete the task.

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



Re: [PHP] regex for multiple line breakes

2009-10-14 Thread Merlin Morgenstern



Ashley Sheridan schrieb:

On Wed, 2009-10-14 at 12:42 +0200, Merlin Morgenstern wrote:


That sounds very logical but does not work unfortunatelly.
The result is the same. It removes all linebreakes but one.
I would like to pass this one:

-
first line

second
third
-

But not this one:
-
third




forth




Fernando Castillo Aparicio schrieb:

You are replacing 1 or more matchs of a new line. To match 2 or more you can use 
"{2,}". It's a range, first number means min matches, second max matches. 
Omitting last number means no max limit.

$data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);




De: Merlin Morgenstern 
Para: php-general@lists.php.net
Enviado: mié,14 octubre, 2009 12:17
Asunto: [PHP] regex for multiple line breakes

Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend 
to insert multiple line breakes. The problem is, that I want to allow 2 line 
breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

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


  



You still have an issue with your regex:

$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

Even if you replace the + with a {2,} you are asking it to match any one
of the characters in the square brackets twice or more and replace it
with a single \n. If your line breaks actually do consist of the \r\n
pattern, then the {2,} will match those two characters, not two sets of
those characters. You might be better off replacing all \r characters
with an empty string, and then matching against the \n character only.

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




Thank you. That worked!
$data[txt] = preg_replace('`[\n]{3,}`',"\n",str_replace("\r", 
"",$data[txt]));


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



Re: [PHP] regex for multiple line breakes

2009-10-14 Thread Fernando Castillo Aparicio
Right. I saw it later. To be completely multiplatform I'd use a grouping: 
(\n|\r|\r\n){2,}. If I'm not wrong, these are all the actual formats for a new 
line.

If we replace \r with a newline we could fail if the text comes from a MAC OS.





De: Ashley Sheridan 
Para: Merlin Morgenstern 
CC: php-general@lists.php.net
Enviado: mié,14 octubre, 2009 12:44
Asunto: Re: [PHP] regex for multiple line breakes

On Wed, 2009-10-14 at 12:42 +0200, Merlin Morgenstern wrote:

> That sounds very logical but does not work unfortunatelly.
> The result is the same. It removes all linebreakes but one.
> I would like to pass this one:
> 
> -
> first line
> 
> second
> third
> -
> 
> But not this one:
> -
> third
> 
> 
> 
> 
> forth
> 
> 
> 
> 
> Fernando Castillo Aparicio schrieb:
> > You are replacing 1 or more matchs of a new line. To match 2 or more you 
> > can use "{2,}". It's a range, first number means min matches, second max 
> > matches. Omitting last number means no max limit.
> > 
> > $data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);
> > 
> > 
> > 
> > 
> > De: Merlin Morgenstern 
> > Para: php-general@lists.php.net
> > Enviado: mié,14 octubre, 2009 12:17
> > Asunto: [PHP] regex for multiple line breakes
> > 
> > Hi there,
> > 
> > I am trying to remove multiple linebreakes from a textarea input. Spammers 
> > tend to insert multiple line breakes. The problem is, that I want to allow 
> > 2 line breaks so basic formating should be allowed.
> > 
> > I am doing this by regex:
> > $data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);
> > 
> > I would need a regex that allows \r\n\r\n, but not more than this.
> > 
> > Thank you for any help,
> > 
> > Merlin
> > 
> > -- PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > 
> >  
> 


You still have an issue with your regex:

$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

Even if you replace the + with a {2,} you are asking it to match any one
of the characters in the square brackets twice or more and replace it
with a single \n. If your line breaks actually do consist of the \r\n
pattern, then the {2,} will match those two characters, not two sets of
those characters. You might be better off replacing all \r characters
with an empty string, and then matching against the \n character only.

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


  

Re: [PHP] regex for multiple line breakes

2009-10-14 Thread Ashley Sheridan
On Wed, 2009-10-14 at 12:42 +0200, Merlin Morgenstern wrote:

> That sounds very logical but does not work unfortunatelly.
> The result is the same. It removes all linebreakes but one.
> I would like to pass this one:
> 
> -
> first line
> 
> second
> third
> -
> 
> But not this one:
> -
> third
> 
> 
> 
> 
> forth
> 
> 
> 
> 
> Fernando Castillo Aparicio schrieb:
> > You are replacing 1 or more matchs of a new line. To match 2 or more you 
> > can use "{2,}". It's a range, first number means min matches, second max 
> > matches. Omitting last number means no max limit.
> > 
> > $data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);
> > 
> > 
> > 
> > 
> > De: Merlin Morgenstern 
> > Para: php-general@lists.php.net
> > Enviado: mié,14 octubre, 2009 12:17
> > Asunto: [PHP] regex for multiple line breakes
> > 
> > Hi there,
> > 
> > I am trying to remove multiple linebreakes from a textarea input. Spammers 
> > tend to insert multiple line breakes. The problem is, that I want to allow 
> > 2 line breaks so basic formating should be allowed.
> > 
> > I am doing this by regex:
> > $data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);
> > 
> > I would need a regex that allows \r\n\r\n, but not more than this.
> > 
> > Thank you for any help,
> > 
> > Merlin
> > 
> > -- PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> > 
> >   
> 


You still have an issue with your regex:

$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

Even if you replace the + with a {2,} you are asking it to match any one
of the characters in the square brackets twice or more and replace it
with a single \n. If your line breaks actually do consist of the \r\n
pattern, then the {2,} will match those two characters, not two sets of
those characters. You might be better off replacing all \r characters
with an empty string, and then matching against the \n character only.

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




Re: [PHP] regex for multiple line breakes

2009-10-14 Thread Merlin Morgenstern

That sounds very logical but does not work unfortunatelly.
The result is the same. It removes all linebreakes but one.
I would like to pass this one:

-
first line

second
third
-

But not this one:
-
third




forth




Fernando Castillo Aparicio schrieb:

You are replacing 1 or more matchs of a new line. To match 2 or more you can use 
"{2,}". It's a range, first number means min matches, second max matches. 
Omitting last number means no max limit.

$data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);




De: Merlin Morgenstern 
Para: php-general@lists.php.net
Enviado: mié,14 octubre, 2009 12:17
Asunto: [PHP] regex for multiple line breakes

Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend 
to insert multiple line breakes. The problem is, that I want to allow 2 line 
breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

-- 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] regex for multiple line breakes

2009-10-14 Thread Fernando Castillo Aparicio
You are replacing 1 or more matchs of a new line. To match 2 or more you can 
use "{2,}". It's a range, first number means min matches, second max matches. 
Omitting last number means no max limit.

$data[txt] = preg_replace('`[\r\n]{2,}`',"\n",$data[txt]);




De: Merlin Morgenstern 
Para: php-general@lists.php.net
Enviado: mié,14 octubre, 2009 12:17
Asunto: [PHP] regex for multiple line breakes

Hi there,

I am trying to remove multiple linebreakes from a textarea input. Spammers tend 
to insert multiple line breakes. The problem is, that I want to allow 2 line 
breaks so basic formating should be allowed.

I am doing this by regex:
$data[txt] = preg_replace('`[\r\n]+`',"\n",$data[txt]);

I would need a regex that allows \r\n\r\n, but not more than this.

Thank you for any help,

Merlin

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


  

Re: [PHP] regex - filtering out chinese utf8 characters

2009-07-30 Thread Jim Lucas
Merlin Morgenstern wrote:
> Hi there,
> 
> I am trying to filter out content that is not ascii. Can I do this with
> regex? For example:
> 
> $regex = '[AZ][09]';
> if (preg_match($regex, $text)) {
> return TRUE;
> }
> else {
> return FALSE;
> }
> 
> The reason I need to do this is that I am doing a mysql query with the
> text and I need to make sure it is not UTF8. Otherwise I do get
> following error:
> 
> Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT)
> and (utf8_general_ci,COERCIBLE) for operation '='
> 
> I am new to regex and would be happy for a jump start to get this fixed.
> 
> Best regards, Merlin
> 

You might want to read up on iconv.  I think it will do what you are
wanting to do.

http://us2.php.net/manual/en/book.iconv.php

specifically...

http://us2.php.net/manual/en/function.iconv.php


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



Re: [PHP] regex - filtering out chinese utf8 characters

2009-07-30 Thread Daniel Kolbo
Merlin Morgenstern wrote:
> Hi there,
> 
> I am trying to filter out content that is not ascii. Can I do this with
> regex? For example:
> 
> $regex = '[AZ][09]';
> if (preg_match($regex, $text)) {
> return TRUE;
> }
> else {
> return FALSE;
> }
> 
> The reason I need to do this is that I am doing a mysql query with the
> text and I need to make sure it is not UTF8. Otherwise I do get
> following error:
> 
> Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT)
> and (utf8_general_ci,COERCIBLE) for operation '='
> 
> I am new to regex and would be happy for a jump start to get this fixed.
> 
> Best regards, Merlin
> 
You prolly have already been here:
http://www.regular-expressions.info/

But if not, that site is certainly useful for all things regex.

Sorry I can't be of more help for your specific question.

dK
`

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



Re: [PHP] regex - filtering out chinese utf8 characters

2009-07-30 Thread Stuart Connolly

Hi Merlin,

I think the pattern you're looking for is '/[a-zA-Z0-9]/' which will  
match all alphanumeric characters.


Cheers

Stuart

On 30 Jul 2009, at 19:13, Merlin Morgenstern wrote:


Hi there,

I am trying to filter out content that is not ascii. Can I do this  
with regex? For example:


$regex = '[AZ][09]';
if (preg_match($regex, $text)) {
return TRUE;
}
else {
return FALSE;
}

The reason I need to do this is that I am doing a mysql query with  
the text and I need to make sure it is not UTF8. Otherwise I do get  
following error:


Error: 		Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and  
(utf8_general_ci,COERCIBLE) for operation '='


I am new to regex and would be happy for a jump start to get this  
fixed.


Best regards, Merlin

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





smime.p7s
Description: S/MIME cryptographic signature


Re: [PHP] Regex not working with ":"

2009-04-22 Thread Merlin Morgenstern



Richard Quadling wrote:

2009/4/22 kyle.smith :

Have you tried escaping the : with a \?

Like:
mb_ereg_replace('^(.*)this is the test\: replace(.*)$', '', $contents
,'UTF-8');

Also, have you tried removing the : and adjusting the input string to
verify your belief that it's the :?

HTH,
Kyle

-Original Message-
From: Merlin Morgenstern [mailto:merli...@fastmail.fm]
Sent: Wednesday, April 22, 2009 4:09 AM
To: php-general@lists.php.net
Subject: [PHP] Regex not working with ":"

Hi there,

I am trying to remove a text which does contain a : inside. Somehow the
regex does not match, no matter what I do:

$contents = mb_ereg_replace('^(.*)this is the test: replace(.*)$', '',
$contents ,'UTF-8');

Looks like this is a result of the :.

Does anybody have an idea how to do this?

Thank you for any help.

Merlin

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




Can you try ..

# Your regular expression could not be converted to the flavor
required by this language:
# A POSIX Extended RE cannot match the start and the end of a line with ^ and $
# A POSIX Extended RE cannot match the start and the end of a line with ^ and $

# Because of this, the code snippet below will not work as you
intended, if at all.

$contents = mb_ereg_replace('^(.*)this is the test: replace(.*)$',
'\1\2', $contents, 'UTF-8');



The warnings above come from RegexBuddy. Considering the PHP examples,
I'm not sure how accurate they are.

Hi there,

thank you for the help. Actually it was due to case sensitivity. Use 
str_ireplace to fix it.


Regards, Merlin

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



Re: [PHP] Regex not working with ":"

2009-04-22 Thread Richard Quadling
2009/4/22 kyle.smith :
> Have you tried escaping the : with a \?
>
> Like:
> mb_ereg_replace('^(.*)this is the test\: replace(.*)$', '', $contents
> ,'UTF-8');
>
> Also, have you tried removing the : and adjusting the input string to
> verify your belief that it's the :?
>
> HTH,
> Kyle
>
> -Original Message-
> From: Merlin Morgenstern [mailto:merli...@fastmail.fm]
> Sent: Wednesday, April 22, 2009 4:09 AM
> To: php-general@lists.php.net
> Subject: [PHP] Regex not working with ":"
>
> Hi there,
>
> I am trying to remove a text which does contain a : inside. Somehow the
> regex does not match, no matter what I do:
>
> $contents = mb_ereg_replace('^(.*)this is the test: replace(.*)$', '',
> $contents ,'UTF-8');
>
> Looks like this is a result of the :.
>
> Does anybody have an idea how to do this?
>
> Thank you for any help.
>
> Merlin
>
> --
> 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
>
>

Can you try ..

# Your regular expression could not be converted to the flavor
required by this language:
# A POSIX Extended RE cannot match the start and the end of a line with ^ and $
# A POSIX Extended RE cannot match the start and the end of a line with ^ and $

# Because of this, the code snippet below will not work as you
intended, if at all.

$contents = mb_ereg_replace('^(.*)this is the test: replace(.*)$',
'\1\2', $contents, 'UTF-8');



The warnings above come from RegexBuddy. Considering the PHP examples,
I'm not sure how accurate they are.
-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

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



RE: [PHP] Regex not working with ":"

2009-04-22 Thread kyle.smith
Have you tried escaping the : with a \?

Like:
mb_ereg_replace('^(.*)this is the test\: replace(.*)$', '', $contents
,'UTF-8');

Also, have you tried removing the : and adjusting the input string to
verify your belief that it's the :?

HTH,
Kyle

-Original Message-
From: Merlin Morgenstern [mailto:merli...@fastmail.fm] 
Sent: Wednesday, April 22, 2009 4:09 AM
To: php-general@lists.php.net
Subject: [PHP] Regex not working with ":"

Hi there,

I am trying to remove a text which does contain a : inside. Somehow the
regex does not match, no matter what I do:

$contents = mb_ereg_replace('^(.*)this is the test: replace(.*)$', '',
$contents ,'UTF-8');

Looks like this is a result of the :.

Does anybody have an idea how to do this?

Thank you for any help.

Merlin

--
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] Regex help please

2009-03-27 Thread Shawn McKenzie
haliphax wrote:
> On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie  wrote:
>> I'm normally OK with regex, especially if I fiddle with it long enough,
>> however I have fiddled with this one so long that I'm either totally
>> missing it or it's something simple.  Does it have anything to do with
>> the backref, or the fact that the value of the backref has a $?  I have:
>>
>> $out = '
>> {$sites}
>> 
>>
>>{Site.id}
>>
>> 
>> {/$sites}';
>>
>> And I want to capture the first {$tag}, everything in between and the
>> last {$/tag}.  I have tried several things and here is my current regex
>> that looks like it should work, but doesn't:
>>
>> preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);
> 
> Shawn,
> 
> First thing I see--your first capture group doesn't include the $, and
> so your final capture group will always fail given your current $out
> (because it's looking for {/sites} instead of {/$sites}). Also, your
> {} are outside of your capture group in \1, but inside in \3. Here's
> what I came up with:
> 
> $out = '
> {$sites}
> 
>
>{Site.id}
>
> 
> {/$sites}';
> $matches = array();
> preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches);
> print_r($matches);
> 
> Produces this:
> 
> Array
> (
> [0] => Array
> (
> [0] => {$sites}
> 
>
>{Site.id}
>
> 
> {/$sites}
> )
> 
> [1] => Array
> (
> [0] => $sites
> )
> 
> [2] => Array
> (
> [0] =>
> 
>
>{Site.id}
>
> 
> 
> )
> 
> [3] => Array
> (
> [0] => /$sites
> )
> 
> )
> 
> Keep in mind, I had to view the page source in order to see the HTML
> tags, but it showed me everything I expected to see.
> 
> HTH,
> 

Yes, thank you.  I was fiddling before I got your post and I came up
with roughly the same.

preg_match_all('|{(\$[^}]+)}(.+){(/\1)}|Us', $out, $matches);

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

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



Re: [PHP] Regex help please

2009-03-27 Thread haliphax
On Fri, Mar 27, 2009 at 9:40 AM, Shawn McKenzie  wrote:
> I'm normally OK with regex, especially if I fiddle with it long enough,
> however I have fiddled with this one so long that I'm either totally
> missing it or it's something simple.  Does it have anything to do with
> the backref, or the fact that the value of the backref has a $?  I have:
>
> $out = '
> {$sites}
> 
>        
>        {Site.id}
>        
> 
> {/$sites}';
>
> And I want to capture the first {$tag}, everything in between and the
> last {$/tag}.  I have tried several things and here is my current regex
> that looks like it should work, but doesn't:
>
> preg_match_all('|{\$([^}]+)}(.+)({/\1})|Us', $out, $matches);

Shawn,

First thing I see--your first capture group doesn't include the $, and
so your final capture group will always fail given your current $out
(because it's looking for {/sites} instead of {/$sites}). Also, your
{} are outside of your capture group in \1, but inside in \3. Here's
what I came up with:

$out = '
{$sites}

   
   {Site.id}
   

{/$sites}';
$matches = array();
preg_match_all('#{(\$[^}]+)}(.*?){(/\1)}#s', $out, $matches);
print_r($matches);

Produces this:

Array
(
[0] => Array
(
[0] => {$sites}

   
   {Site.id}
   

{/$sites}
)

[1] => Array
(
[0] => $sites
)

[2] => Array
(
[0] =>

   
   {Site.id}
   


)

[3] => Array
(
[0] => /$sites
)

)

Keep in mind, I had to view the page source in order to see the HTML
tags, but it showed me everything I expected to see.

HTH,

-- 
// Todd

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



RE: [PHP] Regex

2009-03-27 Thread Jesse.Hazen
Jochem,

To be more specific, the error I get when using this regex is No ending
delimiter '/' found

 
 
 
Thanks,
 
Jesse Hazen
-Original Message-
From: Jochem Maas [mailto:joc...@iamjochem.com] 
Sent: Thursday, March 26, 2009 11:45 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

jesse.ha...@arvatousa.com schreef:
> Hi,
> 
>  
> 
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to
do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
> 

there is, your control-Z is not a Z at all, and it's only printed as ^Z
so you can see it ... it's actually a non-printing char.

try this regexp for stripping control chars:

/[\x00-\x1f]+/

>  
> 
>  
> 
>  
> 
> public function getSelection() {
> 
>  
> 
> $choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN;
> 
> return $choice;
> 
>  
> 
> }
> 
>  
> 
> private function validateChoice($choice) {
> 
>  
> 
> $choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
> 
> return $choice;
> 
>  
> 
> }
> 
>  
> 
>  
> 
>  
> 
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as
ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
> 
>  
> 
>  
> 
>  
> 
> Thanks,
> 
>  
> 
> Jesse Hazen
> 
> 


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



RE: [PHP] Regex

2009-03-27 Thread Jesse.Hazen
Bruce,

Sure thing. So basically what I am trying to accomplish is when this
script runs, a menu is displayed to the user, it looks somewhat like
this:



Welcome
To continue, please select your game mode.

[Mode]  [Description]
A.) Mode A
B.) Mode B
C.) Mode C
D.) Mode D
E.) Mode E
F.) Mode F
Q.) Quit.

To begin, please type the mode letter.

Mode:

 

Then, the below lines of code come into play:


public function getSelection() {

$choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;
return $choice;

}

private function validateChoice($choice) {

$choice = preg_replace("/[\x00-\x1f]+/","",$choice);
return $choice;

}


So now the script is waiting for user input. The next thing to happen,
right after this code, is:


private function validate($choice,$display,$input) {

$valid = false;
while(!$valid) {

switch($choice) {

case "Q":
$display->writeCredits();
sleep(4);
exit(0);
case "A":
$valid = true;
break;
case "B":
$valid = true;
break;
case "C":
$valid = true;
break;
case "D":
$valid = true;
break;
case "E":
$valid = true;
break;
case "F":
$valid = true;
break;
default:
$display->writeInvalidChoice();
$choice =
$input->getSelection();
break;

}

}

return $choice;

}



Now, this is where the script loops infinitely. But, this is only the
first method which validates user input. There are several others.
Basically, my script should accept user input, strip anything that will
not be needed (like anything other than letters and numbers) and then
allow the user to proceed, where the script checks to see if the
numbers/letters they entered correspond to the menu's in any way.

Everything in the script runs perfect, except the fact that the control
statements print infinitely. And while I am sure there is something I
could do to this method to make it not loop infinitely, I would also
need to do this to several other loops. 


 
 
Thanks,
 
Jesse Hazen
-Original Message-
From: bruce [mailto:bedoug...@earthlink.net] 
Sent: Thursday, March 26, 2009 5:23 PM
To: Hazen, Jesse, arvato digital services llc; php-general@lists.php.net
Subject: RE: [PHP] Regex

hi...

if you haven't solved your issue... can you tell me in detail what
you're trying to accomplish? what are the steps to running the script?

thanks


-Original Message-
From: jesse.ha...@arvatousa.com [mailto:jesse.ha...@arvatousa.com]
Sent: Thursday, March 26, 2009 1:23 PM
To: php-general@lists.php.net
Subject: [PHP] Regex


Hi,

 

Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?

 

 

 

 

 

public function getSelection() {

 

$choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;

return $choice;

 

}

 

private function validateChoice($choice) {

 

$choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

return $choice;

 

}

 

 

 

I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and th

RE: [PHP] Regex

2009-03-27 Thread Jesse.Hazen
Jochem,

Thanks, but this regex did not seem to work for me. At least, not on
Windows. I will not be able to test on linux for a few hours. 

I spoke too soon yesterday, too. Control-Z is a problem on Windows, and
not on Linux. However, on linux, control-D is a problem.


 
 
 
Thanks,
 
Jesse Hazen
-Original Message-
From: Jochem Maas [mailto:joc...@iamjochem.com] 
Sent: Thursday, March 26, 2009 11:45 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

jesse.ha...@arvatousa.com schreef:
> Hi,
> 
>  
> 
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to
do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
> 

there is, your control-Z is not a Z at all, and it's only printed as ^Z
so you can see it ... it's actually a non-printing char.

try this regexp for stripping control chars:

/[\x00-\x1f]+/

>  
> 
>  
> 
>  
> 
> public function getSelection() {
> 
>  
> 
> $choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN;
> 
> return $choice;
> 
>  
> 
> }
> 
>  
> 
> private function validateChoice($choice) {
> 
>  
> 
> $choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
> 
> return $choice;
> 
>  
> 
> }
> 
>  
> 
>  
> 
>  
> 
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as
ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
> 
>  
> 
>  
> 
>  
> 
> Thanks,
> 
>  
> 
> Jesse Hazen
> 
> 


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



RE: [PHP] Regex

2009-03-27 Thread Bob McConnell
From: Nitsan Bin-Nun

> If you can point me on the character which control-z creates it would
make
> it easier, I have no idea of it ;)

On Thu, Mar 26, 2009 at 11:06 PM,  wrote:
>>
>> Thanks again. Sad to say, same result.
>>
>> The second option looped an error: Warning: preg_replace():
Compilation
>> failed: nothing to repeat at offset 17

The actual value is 0x1A, and it maps to the ASCII SUB (substitute)
control character. The carrot-Z (^Z) representation is how Unix CLI
software would display it. Many control codes that didn't actually do
anything were printed on the terminals with the carrot prefix. Sometimes
codes that did trigger a function in the terminal would be printed that
way to prevent the function from triggering.

Control-Z is a left over from the CP/M days. It was used to mark the end
of text files, since the original file allocation table (FAT) only
tracked the number of clusters assigned to a file. Some MS-DOS and
MS-Windows applications still tack it on to the end of files. I guess
that's their idea of backward compatibility.

Bob McConnell

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



Re: [PHP] Regex

2009-03-26 Thread Jochem Maas
jesse.ha...@arvatousa.com schreef:
> Hi,
> 
>  
> 
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
> 

there is, your control-Z is not a Z at all, and it's only printed as ^Z
so you can see it ... it's actually a non-printing char.

try this regexp for stripping control chars:

/[\x00-\x1f]+/

>  
> 
>  
> 
>  
> 
> public function getSelection() {
> 
>  
> 
> $choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN;
> 
> return $choice;
> 
>  
> 
> }
> 
>  
> 
> private function validateChoice($choice) {
> 
>  
> 
> $choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
> 
> return $choice;
> 
>  
> 
> }
> 
>  
> 
>  
> 
>  
> 
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
> 
>  
> 
>  
> 
>  
> 
> Thanks,
> 
>  
> 
> Jesse Hazen
> 
> 


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



Re: [PHP] Regex

2009-03-26 Thread Shawn McKenzie
jesse.ha...@arvatousa.com wrote:
> Nistan,
> 
> Just got home, tested on linux. No problem on linux, the control-z just 
> exits. I may just go ahead and post my issue to the PHP windows list to see 
> if anything comes up, and not worry if it doesnt. I appreciate the help very 
> much
> 
> 
> 
> Thanks,
> 
> Jesse

Ctrl z suspends the current process running in the shell in linux.  Not
sure about winbloze.  Probably sends an escape char of some sort.


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

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



RE: [PHP] Regex

2009-03-26 Thread bruce
hi...

if you haven't solved your issue... can you tell me in detail what you're
trying to accomplish? what are the steps to running the script?

thanks


-Original Message-
From: jesse.ha...@arvatousa.com [mailto:jesse.ha...@arvatousa.com]
Sent: Thursday, March 26, 2009 1:23 PM
To: php-general@lists.php.net
Subject: [PHP] Regex


Hi,

 

Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?

 

 

 

 

 

public function getSelection() {

 

$choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;

return $choice;

 

}

 

private function validateChoice($choice) {

 

$choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

return $choice;

 

}

 

 

 

I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
avail. I also tried using both preg_replace() as well as ereg_replace().
I spent a lot of time on the regex section of the PHP manual, but I am
not finding anything. Any advise on how to accomplish this?

 

 

 

Thanks,

 

Jesse Hazen


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

RE: [PHP] Regex

2009-03-26 Thread Jesse.Hazen
Nistan,

Just got home, tested on linux. No problem on linux, the control-z just exits. 
I may just go ahead and post my issue to the PHP windows list to see if 
anything comes up, and not worry if it doesnt. I appreciate the help very much



Thanks,

Jesse

-Original Message-
From: jesse.ha...@arvatousa.com [mailto:jesse.ha...@arvatousa.com]
Sent: Thu 3/26/2009 2:17 PM
To: nitsa...@gmail.com
Cc: php-general@lists.php.net
Subject: RE: [PHP] Regex
 
Nitsan,

 

Not a problem, thanks for the help. So, it is printed as ^Z. However, I
created a little test.php script to accept input and print it back to
me. So, I used control z as my test, and it simply printed a line, and
that's all. So, then I input control z, and then had it print a letter
right after ("a"), and it was just the letter a. no whitespace, no
breaks, nothing. 

 

I even tried one more thing: in the loop (not in the code below) I put
unset($choice), right above where it tells the user their input is
invalid and asks for it again. Even this did not change anything: when
pressing control - z, it looped infinitely.

 

I assumed that \c would be the regex to mend this, as the php manual has
this as "control-x, where x is any character". I even tried every
variation of this, with a key combination like \cZ, or \cz, or \c[zZ],
yet it still does not catch it.

 

 

 

 

Thanks,

 

Jesse Hazen

 



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 2:09 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

If you can point me on the character which control-z creates it would
make it easier, I have no idea of it ;)

I'm sorry mate.

On Thu, Mar 26, 2009 at 11:06 PM,  wrote:

Nitsan,

 

Thanks again. Sad to say, same result.

 

The second option looped an error: Warning: preg_replace(): Compilation
failed: nothing to repeat at offset 17 

 

 

 

 

Thanks,

 

Jesse Hazen



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:58 PM


To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

I have no idea about this control-Z thing, you might want to try it with
UTF (just add the 'u' modificator):
$str = preg_replace("#[^a-zA-Z0-9]+#uis", "", $str);

Or try this:
$str = preg_replace("#(\b[^a-zA-Z0-9]\b?)+#uis", "", $str);

I may be wrong about the second one but it might work...

On Thu, Mar 26, 2009 at 10:51 PM,  wrote:

Nitsan,

 

Thank you very much for the input. However, I just gave this a try and
it still did not strip the control-Z. Therefore, it is still hitting my
loop later and looping infinitely. I am sure I could mend that by
working something into that loop, but there are several loops I would
need to do this on. If I can stop the command at this method, then the
entire script will run perfectly.

 

 

 

 

Thanks,

 

Jesse Hazen

_ 

arvato digital services llc

A Bertelsmann Company

29011 Commerce Center Dr.

Valencia, CA 91355

 

http://arvatodigitalservices.com

 

jesse.ha...@arvatousa.com

Tel. +1 (661) 702-2727

Fax. +1 (661) 775-6478



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:44 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

To filter out everything which is not A-Z, a-z and 0-9 try this regex:

$str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);

On Thu, Mar 26, 2009 at 10:23 PM,  wrote:

Hi,



Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?












   public function getSelection() {



   $choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;

   return $choice;



   }



   private function validateChoice($choice) {



   $choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

   return $choice;



   }







I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
avail. I also tried using both preg_replace() as well as ereg_replace().
I

RE: [PHP] Regex

2009-03-26 Thread Jesse.Hazen
Nitsan,

 

Not a problem, thanks for the help. So, it is printed as ^Z. However, I
created a little test.php script to accept input and print it back to
me. So, I used control z as my test, and it simply printed a line, and
that's all. So, then I input control z, and then had it print a letter
right after ("a"), and it was just the letter a. no whitespace, no
breaks, nothing. 

 

I even tried one more thing: in the loop (not in the code below) I put
unset($choice), right above where it tells the user their input is
invalid and asks for it again. Even this did not change anything: when
pressing control - z, it looped infinitely.

 

I assumed that \c would be the regex to mend this, as the php manual has
this as "control-x, where x is any character". I even tried every
variation of this, with a key combination like \cZ, or \cz, or \c[zZ],
yet it still does not catch it.

 

 

 

 

Thanks,

 

Jesse Hazen

 



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 2:09 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

If you can point me on the character which control-z creates it would
make it easier, I have no idea of it ;)

I'm sorry mate.

On Thu, Mar 26, 2009 at 11:06 PM,  wrote:

Nitsan,

 

Thanks again. Sad to say, same result.

 

The second option looped an error: Warning: preg_replace(): Compilation
failed: nothing to repeat at offset 17 

 

 

 

 

Thanks,

 

Jesse Hazen



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:58 PM


To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

I have no idea about this control-Z thing, you might want to try it with
UTF (just add the 'u' modificator):
$str = preg_replace("#[^a-zA-Z0-9]+#uis", "", $str);

Or try this:
$str = preg_replace("#(\b[^a-zA-Z0-9]\b?)+#uis", "", $str);

I may be wrong about the second one but it might work...

On Thu, Mar 26, 2009 at 10:51 PM,  wrote:

Nitsan,

 

Thank you very much for the input. However, I just gave this a try and
it still did not strip the control-Z. Therefore, it is still hitting my
loop later and looping infinitely. I am sure I could mend that by
working something into that loop, but there are several loops I would
need to do this on. If I can stop the command at this method, then the
entire script will run perfectly.

 

 

 

 

Thanks,

 

Jesse Hazen

_ 

arvato digital services llc

A Bertelsmann Company

29011 Commerce Center Dr.

Valencia, CA 91355

 

http://arvatodigitalservices.com

 

jesse.ha...@arvatousa.com

Tel. +1 (661) 702-2727

Fax. +1 (661) 775-6478



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:44 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

To filter out everything which is not A-Z, a-z and 0-9 try this regex:

$str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);

On Thu, Mar 26, 2009 at 10:23 PM,  wrote:

Hi,



Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?











   public function getSelection() {



   $choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;

   return $choice;



   }



   private function validateChoice($choice) {



   $choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

   return $choice;



   }







I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
avail. I also tried using both preg_replace() as well as ereg_replace().
I spent a lot of time on the regex section of the PHP manual, but I am
not finding anything. Any advise on how to accomplish this?







Thanks,



Jesse Hazen

 

 

 



Re: [PHP] Regex

2009-03-26 Thread Nitsan Bin-Nun
If you can point me on the character which control-z creates it would make
it easier, I have no idea of it ;)

I'm sorry mate.

On Thu, Mar 26, 2009 at 11:06 PM,  wrote:

>  Nitsan,
>
>
>
> Thanks again. Sad to say, same result.
>
>
>
> The second option looped an error: Warning: preg_replace(): Compilation
> failed: nothing to repeat at offset 17
>
>
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jesse Hazen
>   --
>
> *From:* nit...@binnun.co.il [mailto:nit...@binnun.co.il] *On Behalf Of *Nitsan
> Bin-Nun
> *Sent:* Thursday, March 26, 2009 1:58 PM
>
> *To:* Hazen, Jesse, arvato digital services llc
> *Cc:* php-general@lists.php.net
> *Subject:* Re: [PHP] Regex
>
>
>
> I have no idea about this control-Z thing, you might want to try it with
> UTF (just add the 'u' modificator):
> $str = preg_replace("#[^a-zA-Z0-9]+#uis", "", $str);
>
> Or try this:
> $str = preg_replace("#(\b[^a-zA-Z0-9]\b?)+#uis", "", $str);
>
> I may be wrong about the second one but it might work...
>
> On Thu, Mar 26, 2009 at 10:51 PM,  wrote:
>
> Nitsan,
>
>
>
> Thank you very much for the input. However, I just gave this a try and it
> still did not strip the control-Z. Therefore, it is still hitting my loop
> later and looping infinitely. I am sure I could mend that by working
> something into that loop, but there are several loops I would need to do
> this on. If I can stop the command at this method, then the entire script
> will run perfectly.
>
>
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jesse Hazen
>
> _
>
> arvato digital services llc
>
> A Bertelsmann Company
>
> 29011 Commerce Center Dr.
>
> Valencia, CA 91355
>
>
>
> http://arvatodigitalservices.com
>
>
>
> jesse.ha...@arvatousa.com
>
> Tel. +1 (661) 702-2727
>
> Fax. +1 (661) 775-6478
>   --
>
> *From:* nit...@binnun.co.il [mailto:nit...@binnun.co.il] *On Behalf Of *Nitsan
> Bin-Nun
> *Sent:* Thursday, March 26, 2009 1:44 PM
> *To:* Hazen, Jesse, arvato digital services llc
> *Cc:* php-general@lists.php.net
> *Subject:* Re: [PHP] Regex
>
>
>
> To filter out everything which is not A-Z, a-z and 0-9 try this regex:
>
> $str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);
>
> On Thu, Mar 26, 2009 at 10:23 PM,  wrote:
>
> Hi,
>
>
>
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
>
>
>
>
>
>
>
>
>
>
>
>public function getSelection() {
>
>
>
>$choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN;
>
>return $choice;
>
>
>
>}
>
>
>
>private function validateChoice($choice) {
>
>
>
>$choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
>
>return $choice;
>
>
>
>}
>
>
>
>
>
>
>
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jesse Hazen
>
>
>
>
>


RE: [PHP] Regex

2009-03-26 Thread Jesse.Hazen
Nitsan,

 

Thanks again. Sad to say, same result.

 

The second option looped an error: Warning: preg_replace(): Compilation
failed: nothing to repeat at offset 17 

 

 

 

 

Thanks,

 

Jesse Hazen



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:58 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

I have no idea about this control-Z thing, you might want to try it with
UTF (just add the 'u' modificator):
$str = preg_replace("#[^a-zA-Z0-9]+#uis", "", $str);

Or try this:
$str = preg_replace("#(\b[^a-zA-Z0-9]\b?)+#uis", "", $str);

I may be wrong about the second one but it might work...

On Thu, Mar 26, 2009 at 10:51 PM,  wrote:

Nitsan,

 

Thank you very much for the input. However, I just gave this a try and
it still did not strip the control-Z. Therefore, it is still hitting my
loop later and looping infinitely. I am sure I could mend that by
working something into that loop, but there are several loops I would
need to do this on. If I can stop the command at this method, then the
entire script will run perfectly.

 

 

 

 

Thanks,

 

Jesse Hazen

_ 

arvato digital services llc

A Bertelsmann Company

29011 Commerce Center Dr.

Valencia, CA 91355

 

http://arvatodigitalservices.com

 

jesse.ha...@arvatousa.com

Tel. +1 (661) 702-2727

Fax. +1 (661) 775-6478



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:44 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

To filter out everything which is not A-Z, a-z and 0-9 try this regex:

$str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);

On Thu, Mar 26, 2009 at 10:23 PM,  wrote:

Hi,



Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?











   public function getSelection() {



   $choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;

   return $choice;



   }



   private function validateChoice($choice) {



   $choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

   return $choice;



   }







I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
avail. I also tried using both preg_replace() as well as ereg_replace().
I spent a lot of time on the regex section of the PHP manual, but I am
not finding anything. Any advise on how to accomplish this?







Thanks,



Jesse Hazen

 

 



Re: [PHP] Regex

2009-03-26 Thread Nitsan Bin-Nun
I have no idea about this control-Z thing, you might want to try it with UTF
(just add the 'u' modificator):
$str = preg_replace("#[^a-zA-Z0-9]+#uis", "", $str);

Or try this:
$str = preg_replace("#(\b[^a-zA-Z0-9]\b?)+#uis", "", $str);

I may be wrong about the second one but it might work...

On Thu, Mar 26, 2009 at 10:51 PM,  wrote:

>  Nitsan,
>
>
>
> Thank you very much for the input. However, I just gave this a try and it
> still did not strip the control-Z. Therefore, it is still hitting my loop
> later and looping infinitely. I am sure I could mend that by working
> something into that loop, but there are several loops I would need to do
> this on. If I can stop the command at this method, then the entire script
> will run perfectly.
>
>
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jesse Hazen
>
> _
>
> arvato digital services llc
>
> A Bertelsmann Company
>
> 29011 Commerce Center Dr.
>
> Valencia, CA 91355
>
>
>
> http://arvatodigitalservices.com
>
>
>
> jesse.ha...@arvatousa.com
>
> Tel. +1 (661) 702-2727
>
> Fax. +1 (661) 775-6478
>   --
>
> *From:* nit...@binnun.co.il [mailto:nit...@binnun.co.il] *On Behalf Of *Nitsan
> Bin-Nun
> *Sent:* Thursday, March 26, 2009 1:44 PM
> *To:* Hazen, Jesse, arvato digital services llc
> *Cc:* php-general@lists.php.net
> *Subject:* Re: [PHP] Regex
>
>
>
> To filter out everything which is not A-Z, a-z and 0-9 try this regex:
>
> $str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);
>
> On Thu, Mar 26, 2009 at 10:23 PM,  wrote:
>
> Hi,
>
>
>
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
>
>
>
>
>
>
>
>
>
>
>
>public function getSelection() {
>
>
>
>$choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN;
>
>return $choice;
>
>
>
>}
>
>
>
>private function validateChoice($choice) {
>
>
>
>$choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
>
>return $choice;
>
>
>
>}
>
>
>
>
>
>
>
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jesse Hazen
>
>
>


RE: [PHP] Regex

2009-03-26 Thread Jesse.Hazen
Nitsan,

 

Thank you very much for the input. However, I just gave this a try and
it still did not strip the control-Z. Therefore, it is still hitting my
loop later and looping infinitely. I am sure I could mend that by
working something into that loop, but there are several loops I would
need to do this on. If I can stop the command at this method, then the
entire script will run perfectly.

 

 

 

 

Thanks,

 

Jesse Hazen

_ 

arvato digital services llc

A Bertelsmann Company

29011 Commerce Center Dr.

Valencia, CA 91355

 

http://arvatodigitalservices.com
http://arvatodigitalservices.com> 

 

jesse.ha...@arvatousa.com mailto:jesse.ha...@arvatousa.com> 

Tel. +1 (661) 702-2727

Fax. +1 (661) 775-6478



From: nit...@binnun.co.il [mailto:nit...@binnun.co.il] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:44 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@lists.php.net
Subject: Re: [PHP] Regex

 

To filter out everything which is not A-Z, a-z and 0-9 try this regex:

$str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);

On Thu, Mar 26, 2009 at 10:23 PM,  wrote:

Hi,



Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?











   public function getSelection() {



   $choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN;

   return $choice;



   }



   private function validateChoice($choice) {



   $choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

   return $choice;



   }







I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
avail. I also tried using both preg_replace() as well as ereg_replace().
I spent a lot of time on the regex section of the PHP manual, but I am
not finding anything. Any advise on how to accomplish this?







Thanks,



Jesse Hazen

 



Re: [PHP] Regex

2009-03-26 Thread Nitsan Bin-Nun
To filter out everything which is not A-Z, a-z and 0-9 try this regex:

$str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);

On Thu, Mar 26, 2009 at 10:23 PM,  wrote:

> Hi,
>
>
>
> Brand new to regex. So I have a cli which runs a regex on users input,
> to make sure that only 0-9 and A-Z are accepted. It should strip
> everything else. My problem is that when you press control-Z (on
> Windows; I have not yet tested this on linux, and I will, but I would
> like this to be compatible with both OS's) it loops infinitely saying
> invalid data (because of the next method call, which decides what to do
> based on your input). So, here is the input code. Is there a way I can
> ensure that control commands are stripped, here?
>
>
>
>
>
>
>
>
>
>
>
>public function getSelection() {
>
>
>
>$choice =
> $this->validateChoice(trim(strtoupper(fgets(STDIN;
>
>return $choice;
>
>
>
>}
>
>
>
>private function validateChoice($choice) {
>
>
>
>$choice =
> ereg_replace("/[^0-9A-Z]/","",$choice);
>
>return $choice;
>
>
>
>}
>
>
>
>
>
>
>
> I have tried a ton of different things to try and fix this. Tried
> /\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
> avail. I also tried using both preg_replace() as well as ereg_replace().
> I spent a lot of time on the regex section of the PHP manual, but I am
> not finding anything. Any advise on how to accomplish this?
>
>
>
>
>
>
>
> Thanks,
>
>
>
> Jesse Hazen
>
>


Re: [PHP] Regex Problem

2008-12-18 Thread MikeP

""Boyd, Todd M.""  wrote in message 
news:33bde0b2c17eef46acbe00537cf2a190037b7...@exchcluster.ccis.edu...
> -Original Message-
> From: MikeP [mailto:mpel...@princeton.edu]
> Sent: Thursday, December 18, 2008 8:43 AM
> To: php-general@lists.php.net
> Subject: [PHP] Regex Problem
>
> Hello,
> I have  a quirky behavior I'm trying to resolve.
> I have a REGEX that will find a function definition in a php file:
> .function InsertQuery($table,$fields,$values).
> the REGEX is:
> $regex='/function [a-z]* *([$a-zA-Z]*)/';
> the problem is that:
> 1. a slash is automattically put in front of the $. This is good but I
> dont
> know how it gets there.
> 2.a slash is NOT put in front of the parenthesis. Thats bad
> 3. If I try to escape the parenthesis with a \ , I get \\.
> Help

Mike,

Certain characters are considered "special" in RegEx. The $ means "end
of the line," so it must be escaped to avoid confusing its meaning. I
was not sure it had to be escaped within a character set [], but that
may very well be the case. Try this:

$regex = '/function\s+[-_a-z0-9]+\s*\((\s*\$?[-_a-z0-9]+\s*,?)*\s*\)/i';

The word "function" is followed by 1 or more spaces (or tabs). The
function name [-_a-z0-9] can be a combination of alpha-numeric
characters, underscore, and dash. Then, there is optional whitespace
between the name of the function and its parameters. The opening
parenthesis "(" for parameters has been escaped (as has the closing
parenthesis). Then, in a repeatable capture group, the parameters can be
grabbed: Indefinite whitespace, an optional $ (because maybe you're not
using a variable, eh?), one or more alpha-numeric, underscore, or dash
characters, followed by indefinite whitespace and an optional comma (if
there are more arguments). After any number of instances of the capture
group, the regex continues by looking for indefinite whitespace followed
by the closing parenthesis for the function text. The "i" switch at the
end simply means that this regex pattern will be treated as
case-insensitive ('APPLE' == 'apple').

If you're not worried about actually splitting up the function
parameters into capture groups, then you can just use a look-ahead to
ensure that you grab everything up till the LAST parenthesis on the
line.

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?\)(?=.*\)[^)]*)/i';

That one probably needs to be tweaked a bit in order to actually grab
the last parenthesis (instead of just checking for its existence). If
you're willing to trust the text you'll be searching through, you can
probably avoid that "last parenthesis" rule altogether, and make a lazy
regex:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?/i';

Once you get to the opening parenthesis for the function parameters,
that last regex assumes that the rest of the line will also include that
function declaration, and just grabs everything left. If you are using a
regex setup to where the dot marker can also consume newline or carriage
return characters, just throw a "$" at the end of the regex (before the
flags part "/i") in order to tell it just to grab characters until it
reaches the end of the line:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?$/i';

These are all untested, but hopefully I've given you a nudge in the
right direction. If you are still getting strange behavior out of your
PCRE engine, then perhaps you have a different version installed than
what I'm used to--all of the above should work (perhaps with some very
minor changes) in PHP.

HTH,


// Todd

GOT IT!!

Thanks. 



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



RE: [PHP] Regex Problem

2008-12-18 Thread Boyd, Todd M.
> -Original Message-
> From: MikeP [mailto:mpel...@princeton.edu]
> Sent: Thursday, December 18, 2008 8:43 AM
> To: php-general@lists.php.net
> Subject: [PHP] Regex Problem
> 
> Hello,
> I have  a quirky behavior I'm trying to resolve.
> I have a REGEX that will find a function definition in a php file:
> .function InsertQuery($table,$fields,$values).
> the REGEX is:
> $regex='/function [a-z]* *([$a-zA-Z]*)/';
> the problem is that:
> 1. a slash is automattically put in front of the $. This is good but I
> dont
> know how it gets there.
> 2.a slash is NOT put in front of the parenthesis. Thats bad
> 3. If I try to escape the parenthesis with a \ , I get \\.
> Help

Mike,

Certain characters are considered "special" in RegEx. The $ means "end
of the line," so it must be escaped to avoid confusing its meaning. I
was not sure it had to be escaped within a character set [], but that
may very well be the case. Try this:

$regex = '/function\s+[-_a-z0-9]+\s*\((\s*\$?[-_a-z0-9]+\s*,?)*\s*\)/i';

The word "function" is followed by 1 or more spaces (or tabs). The
function name [-_a-z0-9] can be a combination of alpha-numeric
characters, underscore, and dash. Then, there is optional whitespace
between the name of the function and its parameters. The opening
parenthesis "(" for parameters has been escaped (as has the closing
parenthesis). Then, in a repeatable capture group, the parameters can be
grabbed: Indefinite whitespace, an optional $ (because maybe you're not
using a variable, eh?), one or more alpha-numeric, underscore, or dash
characters, followed by indefinite whitespace and an optional comma (if
there are more arguments). After any number of instances of the capture
group, the regex continues by looking for indefinite whitespace followed
by the closing parenthesis for the function text. The "i" switch at the
end simply means that this regex pattern will be treated as
case-insensitive ('APPLE' == 'apple').

If you're not worried about actually splitting up the function
parameters into capture groups, then you can just use a look-ahead to
ensure that you grab everything up till the LAST parenthesis on the
line.

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?\)(?=.*\)[^)]*)/i';

That one probably needs to be tweaked a bit in order to actually grab
the last parenthesis (instead of just checking for its existence). If
you're willing to trust the text you'll be searching through, you can
probably avoid that "last parenthesis" rule altogether, and make a lazy
regex:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?/i';

Once you get to the opening parenthesis for the function parameters,
that last regex assumes that the rest of the line will also include that
function declaration, and just grabs everything left. If you are using a
regex setup to where the dot marker can also consume newline or carriage
return characters, just throw a "$" at the end of the regex (before the
flags part "/i") in order to tell it just to grab characters until it
reaches the end of the line:

$regex = '/function\s+[-_a-z0-9]+\s*\(.*?$/i';

These are all untested, but hopefully I've given you a nudge in the
right direction. If you are still getting strange behavior out of your
PCRE engine, then perhaps you have a different version installed than
what I'm used to--all of the above should work (perhaps with some very
minor changes) in PHP.

HTH,


// Todd

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



Re: [PHP] RegEx to check for non-Latin characters

2008-11-15 Thread Behzad
Thanks everyone. I guess I find the answer:

*// return true if the $str ONLY consists of Arabic characters and
space-character
public function isArabicString($str)
{
return preg_match('/^([\p{Arabic}]|\s)*$/u', $str);
}
*
PHP 5.1.x or higher is required.
@see: http://www.regular-expressions.info/unicode.html

Cheers,
-b


Re: [PHP] RegEx to check for non-Latin characters

2008-11-15 Thread Yeti
Hi Behzad,

I would try a different approach ...

EXAMPLE (UTF-8):

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>


Persia


';
}
function mbStringToArray ($string, $encoding) {
   $strlen = mb_strlen($string);
   while ($strlen) {
   $array[] = mb_substr($string,0,1,$encoding);
   $string = mb_substr($string,1,$strlen,$encoding);
   $strlen = mb_strlen($string);
   }
   return $array;
}
?>



As you can see I'm using the multibyte string functions [1] and split
$username into a character by character array.
Then I use strlen() for which an UTF-8 char has a length > 1. Note:
This might change with PHP6.
It also does not check for Persian characters only yet. You would have
to try something like this ...

EXAMPLE (UTF-8):

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
http://www.w3.org/1999/xhtml";>


Persia


';
   if (mb_strpos($chars, $char, 0, $encoding) !== false) echo $char.' is
a Persian character';
}
function mbStringToArray ($string, $encoding) {
   $strlen = mb_strlen($string);
   while ($strlen) {
   $array[] = mb_substr($string,0,1,$encoding);
   $string = mb_substr($string,1,$strlen,$encoding);
   $strlen = mb_strlen($string);
   }
   return $array;
}
?>



[1] http://in.php.net/manual/en/ref.mbstring.php
[2] http://in.php.net/manual/en/function.strlen.php


Re: [PHP] RegEx to check for non-Latin characters

2008-11-15 Thread Richard Heyes
> For a Form Validation process, I need a function to avoid Latin characters
> to be provided as the first or last name. Since we expect our users to
> enter their personal info in Persian.
>
> Do you know any regular expression to provide this functionality?
> 1) Regex to check whether there are Latin and Numerical characters in a
> string.
> 2) Regex to check whether the string only consists of certain characters.

In a PCRE regex, [\x80-\xFF] will find all extended ASCII chars. Or,
if you wanted all ASCII chars, you could use: [\x00-\xFF] That would
catch space and punctuation as well though. Or you could amend it to
suit. It's in hexadecimal (ie FF == 255)

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 1st)

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



Re: [PHP] Regex validation

2008-10-30 Thread Yeti
ceo wrote:
>var_dump(imap_rfc822_parse_adrlist('"! # $ % &  * + - / = ? ^ _ ` { | } ~"', 
>''));
>This looks like a valid localhost email address to me...

It surely is a valid localhost email address, but what most people
(and the OP) usually need is to validate a full email string with a
local and a domain part.

What should be valid email addresses according to RFC 2822 [1]:
!#$%&*+-/=?^_`{|[EMAIL PROTECTED]
"@"@example.com

Not valid email addresses:
"\"@example.com
@@example.com
- [EMAIL PROTECTED]

Valid email addresses according to the Multipurpose Internet Mail
Extension (MIME) [2]:
[EMAIL PROTECTED]
[EMAIL PROTECTED]

So for people who got to write code that also works on PHP4 it is not
very easy to validate an email address.
Even nice regex attempts like [3] fail since more and more mail
servers support the MIME hieroglyphs.
That's why I was pretty excited about imap_rfc822_parse_adrlist(),
since it runs in PHP4 if installed.
Which clearly is no substitute for the PHP5+ filter functions [4].
If it's just my brain farting and there actually then tell me.

[1] http://www.faqs.org/rfcs/rfc2822.html
[2] http://en.wikipedia.org/wiki/MIME
[3] http://www.addedbytes.com/php/email-address-validation/
[4] http://in.php.net/filter


Re: [PHP] Regex validation

2008-10-30 Thread ceo

var_dump(imap_rfc822_parse_adrlist('"! # $ % &  * + - / = ? ^ _ ` { | } ~"', 
'')); 



This looks like a valid localhost email address to me...



What's wrong with it?

:-v



You may want to check that "host" is non-empty, if you do not expect any 
localhost users, and fail on that condition, however.



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



Re: [PHP] Regex validation

2008-10-30 Thread Yeti
After "ceo" posted about the imap function I was eager to try it out
and got rather disappointed pretty soon.
imap_rfc822_parse_adrlist() should not be used for email validation!

EXAMPLE:


The above code will output:

array(1) {
  [0]=>
  object(stdClass)(2) {
["mailbox"]=>
string(36) "! # $ % &  * + - / = ? ^ _ ` { | } ~"
["host"]=>
string(0) ""
  }
}

Although
"! # $ % &  * + - / = ? ^ _ ` { | } ~"@example.com
would be a valid email address!

Without the '@example.com' it is not.

Have a look at the user comments at [1], where one user has further examples.

[1] http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php

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



Re: [PHP] Regex validation

2008-10-29 Thread Yeti
On Wed, Oct 29, 2008 at 5:36 AM,  <[EMAIL PROTECTED]> wrote:
>
> When it comes to email validation, I would recommend using the IMAP function 
> which will be both fast and correct:
>
> http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php
>
> Otherwise, it's guaranteed that you are having at least some false positives, 
> and probably some false negatives.

Didn't know about those IMAP functions. And they even work in PHP4.
Thanks for telling.

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



Re: [PHP] Regex validation

2008-10-29 Thread ceo

When it comes to email validation, I would recommend using the IMAP function 
which will be both fast and correct:



http://us.php.net/manual/en/function.imap-rfc822-parse-adrlist.php



Otherwise, it's guaranteed that you are having at least some false positives, 
and probably some false negatives.



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



Re: [PHP] Regex validation

2008-10-29 Thread Bastien Koert
On Tue, Oct 28, 2008 at 8:57 PM, VamVan <[EMAIL PROTECTED]> wrote:

> SSO process:
>
> $_POST the Email Address and password
>
> Get Authenticated, Get the COOKIE ( Through Oracle IDM suite SOAP call)
>
> Decrypt the COOKIE ( Through Oracle Enterprise business suite SOAP call)
>
> and get the profile Info
>
> Thats what happens now.
>
> But there is a glitch in the decryption algorithm we currently have. And
> when we decrypt + or some thing else comes with funny characters and does
> not authenticate.
>
> So I need to restrict them for now. When the algorithm gets corrected then
> I
> will use standard RFC.
>
>
>
>
>
Are they not base64 encoded? I have had issues in decrypting elements that
were not base64 encoded as some characters would end up mimicing EOL or
otherwise dropping data

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Regex validation

2008-10-28 Thread Micah Gersten
How is anything but your webserver decrypting the $_POST data?  PHP
should get it after that as is.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



VamVan wrote:
> SSO process:
>
> $_POST the Email Address and password
>
> Get Authenticated, Get the COOKIE ( Through Oracle IDM suite SOAP call)
>
> Decrypt the COOKIE ( Through Oracle Enterprise business suite SOAP call)
>
> and get the profile Info
>
> Thats what happens now.
>
> But there is a glitch in the decryption algorithm we currently have. And
> when we decrypt + or some thing else comes with funny characters and does
> not authenticate.
>
> So I need to restrict them for now. When the algorithm gets corrected then I
> will use standard RFC.
>
>
>
>
> On Tue, Oct 28, 2008 at 5:41 PM, Micah Gersten <[EMAIL PROTECTED]> wrote:
>
>   
>> What are you talking about with a cookie and an E-Mail address?
>>
>> Thank you,
>> Micah Gersten
>> onShore Networks
>> Internal Developer
>> http://www.onshore.com
>>
>>
>>
>> VamVan wrote:
>> 
>>> Yeah, I understand that its allowed in RFC. But unfortunately I use
>>> SSO layer which decrypts the Cookie to get email address.
>>>
>>> This is where it messes up. So I have decided not to allow people to
>>> use that as well.
>>>
>>> Thanks
>>>
>>>
>>>   
>
>   

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



Re: [PHP] Regex validation

2008-10-28 Thread VamVan
SSO process:

$_POST the Email Address and password

Get Authenticated, Get the COOKIE ( Through Oracle IDM suite SOAP call)

Decrypt the COOKIE ( Through Oracle Enterprise business suite SOAP call)

and get the profile Info

Thats what happens now.

But there is a glitch in the decryption algorithm we currently have. And
when we decrypt + or some thing else comes with funny characters and does
not authenticate.

So I need to restrict them for now. When the algorithm gets corrected then I
will use standard RFC.




On Tue, Oct 28, 2008 at 5:41 PM, Micah Gersten <[EMAIL PROTECTED]> wrote:

> What are you talking about with a cookie and an E-Mail address?
>
> Thank you,
> Micah Gersten
> onShore Networks
> Internal Developer
> http://www.onshore.com
>
>
>
> VamVan wrote:
> > Yeah, I understand that its allowed in RFC. But unfortunately I use
> > SSO layer which decrypts the Cookie to get email address.
> >
> > This is where it messes up. So I have decided not to allow people to
> > use that as well.
> >
> > Thanks
> >
> >
>


Re: [PHP] Regex validation

2008-10-28 Thread Micah Gersten
What are you talking about with a cookie and an E-Mail address?

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



VamVan wrote:
> Yeah, I understand that its allowed in RFC. But unfortunately I use
> SSO layer which decrypts the Cookie to get email address.
>
> This is where it messes up. So I have decided not to allow people to
> use that as well.
>
> Thanks
>
>

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



Re: [PHP] Regex validation

2008-10-28 Thread Lupus Michaelis

VamVan a écrit :


This is where it messes up. So I have decided not to allow people to use
that as well.


  By that way, you're making a lot of ennemies on this very list :D

--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

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



Re: [PHP] Regex validation

2008-10-28 Thread VamVan
Yeah, I understand that its allowed in RFC. But unfortunately I use SSO
layer which decrypts the Cookie to get email address.

This is where it messes up. So I have decided not to allow people to use
that as well.

Thanks

On Tue, Oct 28, 2008 at 5:10 PM, Ashley Sheridan
<[EMAIL PROTECTED]>wrote:

> On Tue, 2008-10-28 at 18:07 -0500, Micah Gersten wrote:
> > Keep in mind that ereg will disappear with PHP 6.  You might want to use
> > the preg functions:
> > http://www.making-the-web.com/2007/09/21/becoming-php-6-compatible/
> >
> > Thank you,
> > Micah Gersten
> > onShore Networks
> > Internal Developer
> > http://www.onshore.com
> >
> >
> >
> > VamVan wrote:
> > > Thank Guys,
> > >
> > > I at least got part of it working , not the double words but almost
> > > everything else than that:
> > >
> > > function _email_validate($mail_address){
> > >   $invalid_charset_pattern = "[(*+?)|~<>:;{}/ ]";
> > >   if(ereg($invalid_charset_pattern, $mail_address)){
> > > return false;
> > >   }else{
> > > return true;
> > >   }
> > > }
> > >
> > > Thanks for the inputs
> > >
> > > On Tue, Oct 28, 2008 at 3:31 PM, Nitsan Bin-Nun <[EMAIL PROTECTED]
> > > > wrote:
> > >
> > > Good to know filter_var() exists in PHP5
> > >
> > > Unless you have PHP5 you better validate the string in the way of
> > > checking
> > > if it is fit's to your allowed characters and not checking if it
> > > contains
> > > the NOT allowed charaters.
> > >
> > > You better use: [a-z0-9A-Z\_\.]+ instead of
> > > [^\)\(\*\&[EMAIL PROTECTED] and I
> > > haven't started yet with the weirdy ones
> > >
> > > HTH,
> > > Nitsan
> > >
> > > On Wed, Oct 29, 2008 at 12:10 AM, Yeti <[EMAIL PROTECTED]
> > > > wrote:
> > >
> > > > > If your trying to filter E-Mail addresses, then filter_var is
> > > what you
> > > > > should use:
> > > > >
> > > > > http://php.net/filter_var
> > > >
> > > > If the OP (original poster) got PHP5+
> > > >
> > > > --
> > > > PHP General Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > >
> > > >
> > >
> > >
> >
> Also, according to the official spec, +, < and > are all valid email
> address characters.
>
>
> Ash
> www.ashleysheridan.co.uk
>
>


Re: [PHP] Regex validation

2008-10-28 Thread Ashley Sheridan
On Tue, 2008-10-28 at 18:07 -0500, Micah Gersten wrote:
> Keep in mind that ereg will disappear with PHP 6.  You might want to use
> the preg functions:
> http://www.making-the-web.com/2007/09/21/becoming-php-6-compatible/
> 
> Thank you,
> Micah Gersten
> onShore Networks
> Internal Developer
> http://www.onshore.com
> 
> 
> 
> VamVan wrote:
> > Thank Guys,
> >
> > I at least got part of it working , not the double words but almost
> > everything else than that:
> >
> > function _email_validate($mail_address){
> >   $invalid_charset_pattern = "[(*+?)|~<>:;{}/ ]";
> >   if(ereg($invalid_charset_pattern, $mail_address)){
> > return false;
> >   }else{
> > return true;
> >   }
> > }
> >
> > Thanks for the inputs
> >
> > On Tue, Oct 28, 2008 at 3:31 PM, Nitsan Bin-Nun <[EMAIL PROTECTED]
> > > wrote:
> >
> > Good to know filter_var() exists in PHP5
> >
> > Unless you have PHP5 you better validate the string in the way of
> > checking
> > if it is fit's to your allowed characters and not checking if it
> > contains
> > the NOT allowed charaters.
> >
> > You better use: [a-z0-9A-Z\_\.]+ instead of
> > [^\)\(\*\&[EMAIL PROTECTED] and I
> > haven't started yet with the weirdy ones
> >
> > HTH,
> > Nitsan
> >
> > On Wed, Oct 29, 2008 at 12:10 AM, Yeti <[EMAIL PROTECTED]
> > > wrote:
> >
> > > > If your trying to filter E-Mail addresses, then filter_var is
> > what you
> > > > should use:
> > > >
> > > > http://php.net/filter_var
> > >
> > > If the OP (original poster) got PHP5+
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
> >
> 
Also, according to the official spec, +, < and > are all valid email
address characters.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] Regex validation

2008-10-28 Thread Micah Gersten
Keep in mind that ereg will disappear with PHP 6.  You might want to use
the preg functions:
http://www.making-the-web.com/2007/09/21/becoming-php-6-compatible/

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



VamVan wrote:
> Thank Guys,
>
> I at least got part of it working , not the double words but almost
> everything else than that:
>
> function _email_validate($mail_address){
>   $invalid_charset_pattern = "[(*+?)|~<>:;{}/ ]";
>   if(ereg($invalid_charset_pattern, $mail_address)){
> return false;
>   }else{
> return true;
>   }
> }
>
> Thanks for the inputs
>
> On Tue, Oct 28, 2008 at 3:31 PM, Nitsan Bin-Nun <[EMAIL PROTECTED]
> > wrote:
>
> Good to know filter_var() exists in PHP5
>
> Unless you have PHP5 you better validate the string in the way of
> checking
> if it is fit's to your allowed characters and not checking if it
> contains
> the NOT allowed charaters.
>
> You better use: [a-z0-9A-Z\_\.]+ instead of
> [^\)\(\*\&[EMAIL PROTECTED] and I
> haven't started yet with the weirdy ones
>
> HTH,
> Nitsan
>
> On Wed, Oct 29, 2008 at 12:10 AM, Yeti <[EMAIL PROTECTED]
> > wrote:
>
> > > If your trying to filter E-Mail addresses, then filter_var is
> what you
> > > should use:
> > >
> > > http://php.net/filter_var
> >
> > If the OP (original poster) got PHP5+
> >
> > --
> > 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] Regex validation

2008-10-28 Thread VamVan
Thank Guys,

I at least got part of it working , not the double words but almost
everything else than that:

function _email_validate($mail_address){
  $invalid_charset_pattern = "[(*+?)|~<>:;{}/ ]";
  if(ereg($invalid_charset_pattern, $mail_address)){
return false;
  }else{
return true;
  }
}

Thanks for the inputs

On Tue, Oct 28, 2008 at 3:31 PM, Nitsan Bin-Nun <[EMAIL PROTECTED]> wrote:

> Good to know filter_var() exists in PHP5
>
> Unless you have PHP5 you better validate the string in the way of checking
> if it is fit's to your allowed characters and not checking if it contains
> the NOT allowed charaters.
>
> You better use: [a-z0-9A-Z\_\.]+ instead of [^\)\(\*\&[EMAIL PROTECTED] and
> I
> haven't started yet with the weirdy ones
>
> HTH,
> Nitsan
>
> On Wed, Oct 29, 2008 at 12:10 AM, Yeti <[EMAIL PROTECTED]> wrote:
>
> > > If your trying to filter E-Mail addresses, then filter_var is what you
> > > should use:
> > >
> > > http://php.net/filter_var
> >
> > If the OP (original poster) got PHP5+
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>


Re: [PHP] Regex validation

2008-10-28 Thread Nitsan Bin-Nun
Good to know filter_var() exists in PHP5

Unless you have PHP5 you better validate the string in the way of checking
if it is fit's to your allowed characters and not checking if it contains
the NOT allowed charaters.

You better use: [a-z0-9A-Z\_\.]+ instead of [^\)\(\*\&[EMAIL PROTECTED] and I
haven't started yet with the weirdy ones

HTH,
Nitsan

On Wed, Oct 29, 2008 at 12:10 AM, Yeti <[EMAIL PROTECTED]> wrote:

> > If your trying to filter E-Mail addresses, then filter_var is what you
> > should use:
> >
> > http://php.net/filter_var
>
> If the OP (original poster) got PHP5+
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Regex validation

2008-10-28 Thread Yeti
> If your trying to filter E-Mail addresses, then filter_var is what you
> should use:
>
> http://php.net/filter_var

If the OP (original poster) got PHP5+

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



RE: [PHP] Regex validation

2008-10-28 Thread Boyd, Todd M.
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of Richard Heyes
> Sent: Tuesday, October 28, 2008 4:30 PM
> To: VamVan
> Cc: php List
> Subject: Re: [PHP] Regex validation
> 
> > Hello Team of Nerds,
> 
> Not the best way  to start your request for help.
> 
> > I need help in writing a regular expression for this:
> >
> > invalid character set is:
> >
> >
>
INVALID_STRING={"/","*","+","(",")","'\'","<",">",",",":",";","~","..",
> ".@","@."};
> >
> > I want to a pregmatch for these characters on my whole email address
> and if
> > match is found I need to return false.
> 
> Based on what you've said, you might not need a regex, there may well
> be an str* function that you can use. Maybe strpos().

I thought so at first, but it appears the final 3 array members of
INVALID_STRING are two characters wide. That could, of course, be
handled with a different algorithm from the other, one-character
members.


Todd Boyd
Web Programmer



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



Re: [PHP] Regex validation

2008-10-28 Thread Micah Gersten

VamVan wrote:
> Hello Team of Nerds,
>
> I need help in writing a regular expression for this:
>
> invalid character set is:
>
> INVALID_STRING={"/","*","+","(",")","'\'","<",">",",",":",";","~","..",".@","@."};
>
> I want to a pregmatch for these characters on my whole email address and if
> match is found I need to return false.
>
> Thank you
>
>   

If your trying to filter E-Mail addresses, then filter_var is what you
should use:

http://php.net/filter_var

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com




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



Re: [PHP] Regex validation

2008-10-28 Thread Richard Heyes
> Hello Team of Nerds,

Not the best way  to start your request for help.

> I need help in writing a regular expression for this:
>
> invalid character set is:
>
> INVALID_STRING={"/","*","+","(",")","'\'","<",">",",",":",";","~","..",".@","@."};
>
> I want to a pregmatch for these characters on my whole email address and if
> match is found I need to return false.

Based on what you've said, you might not need a regex, there may well
be an str* function that you can use. Maybe strpos().

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated October 25th)

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



Re: [PHP] Regex validation

2008-10-28 Thread Daniel P. Brown
On Tue, Oct 28, 2008 at 4:10 PM, VamVan <[EMAIL PROTECTED]> wrote:
> Hello Team of Nerds,
>
> I need help in writing a regular expression for this:
>
> invalid character set is:
>
> INVALID_STRING={"/","*","+","(",")","'\'","<",">",",",":",";","~","..",".@","@."};

Then you need to STFW and RTFM.  PHP uses Perl-style regexp's, by the way.

The best place to start, in my opinion, and a site you should
bookmark, is Jan Goyvaerts'[1] site.  He's done a fantastic job for
people of varying degrees of /regexpertise/:

http://www.regular-expressions.info/


1: [MEDIA] http://www.just-great-software.com/special/JanGoyvaerts.wav

-- 

http://www.parasane.net/ [New Look]
[EMAIL PROTECTED] || [EMAIL PROTECTED]

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



RE: [PHP] Regex help

2008-09-09 Thread Boyd, Todd M.
> -Original Message-
> From: Jason Pruim [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, September 09, 2008 7:30 AM
> To: PHP-General List
> Subject: [PHP] Regex help
> 
> Hey everyone,
> 
> Not completely specific to php but I know you guys know regex's
> better then I do! :)
> 
> I am attempting to match purl.schreurprinting.com/jasonpruim112 to
> purl.schreurprinting.com/p.php?purl=jasonpruim112
> 
> Here are my current matching patterns:
> 
>  RewriteRule /(.*) "/volumes/raider/webserver/
> documents/dev/schreurprinting.com/p.php?purl=$
> #   RewriteRule /(*.) "/purl.schreurprinting.com/$1"
> #   RewriteRule /(mail.php?purl=*) "/
> purl.schreurprinting.com/mail.php?purl=$1"
> 
> Yes I am doing this for apache's mod_rewrite, but my question is much
> more specific to regex's at this point :)
> 
> Any ideas where I am going wrong? it seems like it should be fairly
> simple to do, but I don't know regex's at all :)

http://www.regular-expressions.info ... that's how I learned. :)
Anyway... your match might be something like:

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

And the rewrite...

"/p.php?purl=$1"

To break it down, the match is looking for "The beginning of the line,
followed by a forward slash, followed by (begin capture group) 1 or more
characters that are not a forward slash or a period (end capture group)
followed by an optional forward slash, followed by the end of the line."

The rewrite is fairly straightforward.

I went 100% generic with the match due to your following e-mail that
stated "jasonpruim112" could be any username. If "112" is necessary for
the match, it would be more like:

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

Hope this helps,


Todd Boyd
Web Programmer




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



  1   2   3   4   5   6   >