php-general Digest 1 Jan 2011 00:09:58 -0000 Issue 7110

2010-12-31 Thread php-general-digest-help

php-general Digest 1 Jan 2011 00:09:58 - Issue 7110

Topics (messages 310418 through 310438):

Re: Do you trim() usernames and passwords?
310418 by: Nathan Rixham

Re: Regex for telephone numbers
310419 by: Nathan Rixham
310420 by: Ethan Rosenberg
310422 by: a...@ashleysheridan.co.uk
310423 by: Ethan Rosenberg
310426 by: Nathan Rixham
310427 by: Al
310428 by: a...@ashleysheridan.co.uk
310429 by: Al
310430 by: Per Jessen
310431 by: Per Jessen
310432 by: Daniel P. Brown
310434 by: Dmitriy Ugnichenko
310435 by: Daniel Brown
310436 by: Steve Staples
310438 by: Jim Lucas

Job Search
310421 by: Ethan Rosenberg
310424 by: Daniel Brown
310425 by: Greg Bair

Re: goto - My comments
310433 by: Govinda

Re: memory usage/release  GC
310437 by: Tommy Pham

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---

Tamara Temple wrote:
Sorry, I was mislead by your use of the phrase Users should not be 
copy-pasting passwords or usernames above. I'd love to hear what you 
think is an alternative to identifying with web app that keeps track of 
information about someone that is more secure.


client side ssl certificates, they force http+tls (thus encryption over 
the wire and no chance of middleman attacks) and no usernames or 
passwords need to be passed, as you identify people by the public key 
held in their certificate, the TLS process ensures they have the private 
key.
---End Message---
---BeginMessage---

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.
---End Message---
---BeginMessage---

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



---End Message---
---BeginMessage---
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 eth...@earthlink.net
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: Nathan Rixham nrix...@gmail.com
Cc: php-gene...@lists.php.net php-gene...@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 

Re: [PHP] memory usage/release GC

2010-12-31 Thread Peter Lind
On Dec 31, 2010 6:20 AM, Tommy Pham tommy...@gmail.com wrote:

 Hi folks,

 With the recent thread about password  security, I wrote a small quick
 script to generate a random or all possible passwords based on certain
 parameters for a brute force use.  On a very long running execution for a
 complex password in length with full use of the keys (94 characters),
 including upper case, the script seems to consumes more memory (shown in
 Windows task manager) as time progress.  Below are snippets from the
script
 file that does the workload:

 while (!$this-isMax())
 {
for ($b = 0; $b = $this-pwdLength; $b++)
{
if ($this-counter[$b]  $this-max)
{
$this-pwd[$b] =
 $this-charList[$this-counter[$b]];
$this-counter[$b]++;
break;
}
else
{
$this-counter[$b] = 1;
$this-pwd[$b] = $this-charList[0];
}
}
 }

 private function isMax()
 {
for ($a = $this-pwdLength-1; $a=0; $a--)
{
if ($this-counter[$a]  $this-max) return false;
}
return true;
 }

 Could someone please tell me why the above code consumes additional memory
 as time progress for the execution of the while loop?  Researching PHP GC
on
 google didn't shed light on problem.  Generating all possible combinations
 for 20 length with 94 possibilities each, the script easily consumes more
 than 1GB RAM in few minutes.  BTW, gc_enabled() reports on.

 Thanks,
 Tommy



Are you storing or throwing away the passwords? Also, lots of code is
missing from that post, no idea if you've got a memory leak in the rest of
the code

Regards
Peter


Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-31 Thread Nathan Rixham

Tamara Temple wrote:


On Dec 28, 2010, at 2:11 PM, Joshua Kehn wrote:


Specifically:


Dotan Cohen wrote:

I seem to have an issue with users who copy-paste their usernames and
passwords coping and pasting leading and trailing space characters.


Users should not be copy-pasting passwords or usernames. Do not 
compromise a system to cater to bad [stupid, ignorant, you pick] 
users. If this is an issue then educate the users.


I'm sorry, but this is just bloody stupid. I keep my usernames and 
randomly generated, very long passwords in a password keeper. If you're 
not going to let me copy paste them into a web page, i'm just not going 
to ever use your application. Copy/pasting is something that happens on 
the *local* machine -- it never goes out to the net. By forcing people 
to type in their user names and passwords you are going to cause them to 
enter easily-remembered, and typically easily-crackable combinations. 
What is the possible logic for disallowing someone to paste in their 
usernames/passwords???


Tamara, you're missing half the context, the whole point was don't send 
username and password combo's in plaintext via email to users (thus 
forcing them to copy and paste from email) - this point was made but 
then that context has been stripped from the above email, obviously 
copy+pasting from a password keeper and such like is totally fine..



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



Re: [PHP] Re: Do you trim() usernames and passwords?

2010-12-31 Thread Nathan Rixham

Tamara Temple wrote:
Sorry, I was mislead by your use of the phrase Users should not be 
copy-pasting passwords or usernames above. I'd love to hear what you 
think is an alternative to identifying with web app that keeps track of 
information about someone that is more secure.


client side ssl certificates, they force http+tls (thus encryption over 
the wire and no chance of middleman attacks) and no usernames or 
passwords need to be passed, as you identify people by the public key 
held in their certificate, the TLS process ensures they have the private 
key.


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



[PHP] Job Search

2010-12-31 Thread Ethan Rosenberg

Dear list -

I am an entry level data base programmer [PHP/MySQL HTTP/CSS] looking 
for work in the NY metropolitan area.  Any ideas?


Should we have a job search board?

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 eth...@earthlink.net
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: Nathan Rixham nrix...@gmail.com
Cc: php-general@lists.php.net 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 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.ukhttp://www.ashleysheridan.co.uk

- Reply message -
From: Ethan Rosenberg eth...@earthlink.net
Date: Fri, Dec 31, 2010 14:03
Subject: [PHP] Regex for telephone numbers
To: Nathan Rixham nrix...@gmail.com
Cc: php-general@lists.php.net 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/)http://www.php.net/)
To unsubscribe, visit: 
http://www.php.net/unsub.phphttp://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] Job Search

2010-12-31 Thread Daniel Brown
On Fri, Dec 31, 2010 at 09:11, Ethan Rosenberg eth...@earthlink.net wrote:
 Dear list -

 I am an entry level data base programmer [PHP/MySQL HTTP/CSS] looking for
 work in the NY metropolitan area.  Any ideas?

Search Google, but trust me, you're going to need more experience
than entry-level to pick up a job around here, unless you're working
remotely, and for relatively-minimal wage for the industry.  I'm out
in Scranton, and even here, when companies hire for someone with
skills in those areas, they want a minimum of 2-4 years.

 Should we have a job search board?

No.  Not only would that be reinventing the wheel, but if we did
it, it would be square.  Many others can do it much better than we
would have any interest in doing.  That said, I'd highly recommend
checking your local CraigsList, in the Gigs section, for computer
and web jobs.  Sometimes they have some quick one-off ones that can
not only help you build experience, but also start building your
roster of contacts.

-- 
/Daniel P. Brown
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] Job Search

2010-12-31 Thread Greg Bair
On Fri, 31 Dec 2010 09:11:31 -0500
Ethan Rosenberg eth...@earthlink.net wrote:

 Dear list -
 
 I am an entry level data base programmer [PHP/MySQL HTTP/CSS] looking 
 for work in the NY metropolitan area.  Any ideas?
 
 Should we have a job search board?
 
 Ethan

phpdeveloper.org has a nice job board at http://jobs.phpdeveloper.org/.

-- 
Greg Bair
PHP Developer

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



[PHP] Re: Regex for telephone numbers

2010-12-31 Thread Al



On 12/29/2010 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)]



Regex is over-kill.

$phoneNum = preg_replace(%\D%, '', $phoneNum);//Remove everything except 
digits

$phoneNum = ltrim($phoneNum,'1');//Remove leading 1s

if(strlen($phoneValue) != 10)
{
throw new Exception(Phone number must be 10 digits, without leading a 1. Check 
your entry carefull);

}

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



Re: [PHP] Re: Regex for telephone numbers

2010-12-31 Thread a...@ashleysheridan.co.uk
Erm, you say regex is overkill, then use one in your example!

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

- Reply message -
From: Al n...@ridersite.org
Date: Fri, Dec 31, 2010 15:53
Subject: [PHP] Re: Regex for telephone numbers
To: php...@lists.php.net, php-general@lists.php.net



On 12/29/2010 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)]


Regex is over-kill.

$phoneNum = preg_replace(%\D%, '', $phoneNum);//Remove everything except 
digits

$phoneNum = ltrim($phoneNum,'1');//Remove leading 1s

if(strlen($phoneValue) != 10)
 {
throw new Exception(Phone number must be 10 digits, without leading a 1. Check 
your entry carefull);
 }

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



Re: [PHP] Re: Regex for telephone numbers

2010-12-31 Thread Al



On 12/31/2010 11:10 AM, a...@ashleysheridan.co.uk wrote:

Erm, you say regex is overkill, then use one in your example!

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

- Reply message -
From: Aln...@ridersite.org
Date: Fri, Dec 31, 2010 15:53
Subject: [PHP] Re: Regex for telephone numbers
To:php...@lists.php.net,php-general@lists.php.net



On 12/29/2010 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)]



Regex is over-kill.

$phoneNum = preg_replace(%\D%, '', $phoneNum);//Remove everything except 
digits

$phoneNum = ltrim($phoneNum,'1');//Remove leading 1s

if(strlen($phoneValue) != 10)
  {
throw new Exception(Phone number must be 10 digits, without leading a 1. Check
your entry carefull);
  }



Save and use the resultant $phoneNum; It is all that needs to be saved and used. 
Dashes, spaces and () are superfluous. Only the 10 digits are required for his 
application.


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

2010-12-31 Thread Per Jessen
Al wrote:

 
 
 On 12/29/2010 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)]

 
 Regex is over-kill.

You've just used one any way:

 $phoneNum = preg_replace(%\D%, '', $phoneNum);//Remove everything except 
 digits 
 
 $phoneNum = ltrim($phoneNum,'1');//Remove leading 1s
 
 if(strlen($phoneValue) != 10)
  {
 throw new Exception(Phone number must be 10 digits, without leading a
 1. Check your entry carefull);
  }

One regex and two function calls when one regex would have sufficed?


-- 
Per Jessen, Zürich (2.6°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 Daniel P. Brown
On Fri, Dec 31, 2010 at 11:04, Per Jessen p...@computer.org 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).

-- 
/Daniel P. Brown
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] goto - My comments

2010-12-31 Thread Govinda
Would you please look at the code you wrote again.  I must have  
botched it, because both the age and kitten form still are on the  
same page.  The age page should appear, the data should be accepted  
and then the kitten page should appear.


Ethan



Hi Ethan,

I don't mean to get in between you and Jim (or anyone else here).  You  
want your page to just work.. and Jim offered you a working solution..  
nice!


But my suggestion is to drop that task for a day..  *totally start  
over* .. SUPER simple..  See if you can make a *tiny* form appear on a  
page and then when submitted show the next form.. etc.. just as you  
need the flow to go.  Learn the concepts and logic structures involved  
to make that happen.  If you focus on just this one thing then you  
will get it without too much more trouble.. and then you will OWN it  
and be able to apply it to your real production task.  If you get  
stuck while writing your SIMPLE strung-together test forms, then ask  
about where you are stuck; what is it exactly that you do not  
understand.  Just saying, effectively, It does not work shows you  
are over your head and need to back up and break down the problem into  
smaller parts.  Don't worry, the smaller parts will prove to be easy,  
once actually seen for what they are!  My PHP familiarity is not even  
20% of what Jim and others here have, but I can and certainly will  
help you reach working code, so I guarantee you'll have help, if you  
start from the beginning.   I'll be here all day today, and back on  
monday... to answer your posts.



Govinda


--
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 eth...@earthlink.netwrote:

 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 Brown
On Fri, Dec 31, 2010 at 12:05, Dmitriy Ugnichenko
mitya.ugniche...@gmail.com 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.

-- 
/Daniel P. Brown
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 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 eth...@earthlink.net 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:
 
 ?php
 
 $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] memory usage/release GC

2010-12-31 Thread Tommy Pham
On Fri, Dec 31, 2010 at 2:02 AM, Peter Lind peter.e.l...@gmail.com wrote:

 On Dec 31, 2010 6:20 AM, Tommy Pham tommy...@gmail.com wrote:

 Hi folks,

 With the recent thread about password  security, I wrote a small quick
 script to generate a random or all possible passwords based on certain
 parameters for a brute force use.  On a very long running execution for a
 complex password in length with full use of the keys (94 characters),
 including upper case, the script seems to consumes more memory (shown in
 Windows task manager) as time progress.  Below are snippets from the
 script
 file that does the workload:

 while (!$this-isMax())
 {
        for ($b = 0; $b = $this-pwdLength; $b++)
        {
                if ($this-counter[$b]  $this-max)
                {
                        $this-pwd[$b] =
 $this-charList[$this-counter[$b]];
                        $this-counter[$b]++;
                        break;
                }
                else
                {
                        $this-counter[$b] = 1;
                        $this-pwd[$b] = $this-charList[0];
                }
        }
 }

 private function isMax()
 {
        for ($a = $this-pwdLength-1; $a=0; $a--)
        {
                if ($this-counter[$a]  $this-max) return false;
        }
        return true;
 }

 Could someone please tell me why the above code consumes additional memory
 as time progress for the execution of the while loop?  Researching PHP GC
 on
 google didn't shed light on problem.  Generating all possible combinations
 for 20 length with 94 possibilities each, the script easily consumes more
 than 1GB RAM in few minutes.  BTW, gc_enabled() reports on.

 Thanks,
 Tommy



 Are you storing or throwing away the passwords? Also, lots of code is
 missing from that post, no idea if you've got a memory leak in the rest of
 the code

 Regards
 Peter

Hi Peter,

Thanks for the reply.  After I sent the e-mail last night, I did a
little debugging.  As it turns out, xdebug was the culprit.  I gotta
remember to disable xdebug while coding...  Anyway, here's the full
code.  Anyone is welcome to use it.

$timeStart = microtime(true);

//set_time_limit(0);
ini_set('max_execution_time', 0);
ini_set('memory_limit', -1);
class PwdGen
{
const ALPHA_LOWER = 'abcdefghijklmnopqrstuvwxyz';
const ALPHA_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const NUMERIC = '0123456789';
const SPECIALS = '!...@#$%^*()`~-_=+[]\{}|;:\',./?';
private $chars;
private $charList;
private $max;
private $pwdLength;
private $pwdList; // array
private $pwd;
private $counter; // array
private $insertDb = false;

public function __construct($pwdLength = 8, $useUpper = true,
$useNumeric = true, $useSpecials = true, $insertDb = true, $specials =
'')
{
$this-insertDb = $insertDb;
$this-pwdLength = intval($pwdLength);
$this-chars = self::ALPHA_LOWER;
if ($useUpper) $this-chars .= self::ALPHA_UPPER;
if ($useNumeric) $this-chars .= self::NUMERIC;
if ($useSpecials) $this-chars .= empty($specials) ? 
self::SPECIALS
: $specials;
}
private function init()
{
$this-charList = str_split($this-chars, 1);
$this-max = sizeof($this-charList);
$this-pwd = str_split(str_repeat($this-charList[0], 
$this-pwdLength), 1);

$this-pwdList = array(); // array
$this-counter = array();
for ($a = 0; $a  $this-pwdLength; $a++)
$this-counter[$a] = 1;
$this-counter[$this-pwdLength-1] = 0;
}
public function setPasswordLength($pwdLength)
{
$this-pwdLength = intval($pwdLength);
}
public function setUseChars($useUpper = true, $useNumeric = true,
$useSpecials = true, $specials = '')
{
$this-chars = self::ALPHA_LOWER;
if ($useUpper) $this-chars .= self::ALPHA_UPPER;
if ($useNumeric) $this-chars .= self::NUMERIC;
if ($useSpecials) $this-chars .= empty($specials) ? 
self::SPECIALS
: $specials;
}
public function getRandom()
{
$this-init();
for ($a = 0; $a  $this-pwdLength; $a++)
$this-pwd[$a] = $this-charList[rand(0, $this-max - 
1)];
$pwd = implode('', $this-pwd);
$output = $this-max.': '.$this-chars.' ('.pow($this-max,
$this-pwdLength).') '.PHP_EOL.$pwd.PHP_EOL;
return $output;
}
public function getAll($continue = true)
{
$this-init();
$sql = 'INSERT INTO `password`(`guid`, `length`, `password`,
`counter`, `date_added`) VALUES (BinUUID(), '.$this-pwdLength.', ?,
?, now())';

$pwd = '';
$counter = '';
 

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 eth...@earthlink.net 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:
 
 ?php
 
 $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 Daniel P. Brown
On Fri, Dec 31, 2010 at 19:09, Jim Lucas li...@cmsws.com 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.

-- 
/Daniel P. Brown
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