Re: [PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread Ross Hansen
There is the w3sxools website that has a php quiz.
Http://www.w3schools.com/php/default.asp 

This site has many other languages that offer quizes also

- Reply message -
From: "Mike Hansen" 
To: 
Subject: [PHP] Any free online tests to test my PHP knowledge?
Date: Fri, Sep 23, 2011 3:51 am


On 9/22/2011 1:11 PM, George Langley wrote:
> On 2011-09-22, at 11:53 AM, Mike Hansen wrote:
>
>> Does anyone know of a site that has an online test of PHP skills? I'd like 
>> to review my PHP knowledge.
>>
>> I've already run across this site: 
>> http://vladalexa.com/scripts/php/test/test_php_skill.html
> 
>   Doesn't appear to be working. Just has a link to some blog and no 
> results.
>
> George
>
>
Same here. I found that out after taking the test.

Mike

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




Re: [PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread Paul Halliday
On Thu, Sep 22, 2011 at 6:44 PM, Paul M Foster  wrote:
> On Thu, Sep 22, 2011 at 11:53:54AM -0600, Mike Hansen wrote:
>
>> Does anyone know of a site that has an online test of PHP skills?
>> I'd like to review my PHP knowledge.
>>
>> I've already run across this site:
>> http://vladalexa.com/scripts/php/test/test_php_skill.html
>>
>> Thanks,
>>
>> Mike
>
> I've had to take online PHP tests twice for recruiters. My beefs are 1)
> they're not "open book", and I code with a tab open to php.net all the
> time. (Who remembers which parameter comes first on which function call:
> needle or haystack?) 2) They never tell you *what* you got wrong. That's
> not very helpful.
>
> Mind you, these aren't "free" tests like you're probably talking about.
> They are through a vendor whom the recruiter probably pays to administer
> the test.
>
> Incidentally, despite having written an awful lot of working PHP code, I
> don't do well on those tests. Helps my confidence a lot, as you can
> imagine.
>
> Paul
>

Geez, closed book? I would have a hard time throwing:

?>pph

together.

-- 
Paul Halliday
http://www.squertproject.org/

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



Re: [PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread Paul M Foster
On Thu, Sep 22, 2011 at 11:53:54AM -0600, Mike Hansen wrote:

> Does anyone know of a site that has an online test of PHP skills?
> I'd like to review my PHP knowledge.
> 
> I've already run across this site:
> http://vladalexa.com/scripts/php/test/test_php_skill.html
> 
> Thanks,
> 
> Mike

I've had to take online PHP tests twice for recruiters. My beefs are 1)
they're not "open book", and I code with a tab open to php.net all the
time. (Who remembers which parameter comes first on which function call:
needle or haystack?) 2) They never tell you *what* you got wrong. That's
not very helpful.

Mind you, these aren't "free" tests like you're probably talking about.
They are through a vendor whom the recruiter probably pays to administer
the test.

Incidentally, despite having written an awful lot of working PHP code, I
don't do well on those tests. Helps my confidence a lot, as you can
imagine.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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



Re: [PHP] What determines your use of the type of DB framework/abstract?

2011-09-22 Thread Paul M Foster
On Thu, Sep 22, 2011 at 11:31:54AM -0700, Jamie Krasnoo wrote:

> Sorry, not sure if the first part of the conversation made it to the list.
> 
> I will be looking in to Symfony. I'm well versed with ZF and Zend_Db.
> I'm also somewhat versed with Doctrine and integrating it with ZF. My
> question isn't whether Doctrine is a part *of* that framework but
> rather on *what* and *when* it is appropriate to *use* or *substitute*
> something like Doctrine instead of using straight pdo or mysqli or the
> abstract that came with that particular framework. Substituting
> Doctrine or some other abstract could complicate a project rather than
> help.

Doctrine is more than just an abstraction layer. Well, no, but it's also
an ORM framework. That alone would kill it for me.

I built my own wrapper around PDO, that I use whenever possible. Main
reason: it makes my interface the same, whether I'm using MySQL or
PostgreSQL. That simplifies things for me. Why not just use PDO? I think
PDO, for all its assets, has kind of a clunky interface. When I'm doing
work internally, I use PostgreSQL. But for customers, I'm generally
forced to use MySQL. So having the same interface for both (for the most
part) eases the work. As for ORMs, I'm old skool; my preference is to
use straight SQL where possible. I think it makes you think more
carefully about your database structure and the type of queries you do.
And sooner or later, ORM gets in the way of multi-table foreign-key
reliant queries.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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



Re: [PHP] What determines your use of the type of DB framework/abstract?

2011-09-22 Thread Lester Caine

Jamie Krasnoo wrote:

My question isn't whether Doctrine is a part*of*  that framework but
rather on*what*  and*when*  it is appropriate to*use*  or*substitute*
something like Doctrine instead of using straight pdo or mysqli or the
abstract that came with that particular framework. Substituting
Doctrine or some other abstract could complicate a project rather than
help.


Jamie
The first question is probably "do you need cross database operation?" If the 
answer is no, then there is little point moving to an abstraction layer, you are 
better sticking with your database of choice ...


If the requirement is to allow cross database working, then one needs to address 
the SQL as well as the simple data stuff which PDO attempt. I've been using 
ADOdb for a long time now and have also successfully moved projects TO that when 
wanting to allow them to work with my own preferred database. It successfully 
maps many SQL differences and tidies up those problems.


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

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



Re: [PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread Mike Hansen

On 9/22/2011 1:11 PM, George Langley wrote:

On 2011-09-22, at 11:53 AM, Mike Hansen wrote:


Does anyone know of a site that has an online test of PHP skills? I'd like to 
review my PHP knowledge.

I've already run across this site: 
http://vladalexa.com/scripts/php/test/test_php_skill.html


Doesn't appear to be working. Just has a link to some blog and no 
results.

George



Same here. I found that out after taking the test.

Mike

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



Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Robert Williams
[Redirecting thread back to the list for the benefit of others.]

On 9/22/11 13:38, "Eric"  wrote:


>So is $_POST["username"][0] appropriate or does that only work
>with normal variables?

As far as this sort of manipulation goes, $_POST is just like any other
variable. Referencing the 0th element of any string will give you the
first character, if there is one. (If there isn't one, you'll generate a
PHP warning or notice for trying to read out-of-bounds.)

>and would this be valid,
>$i = 0;
>while($_POST["username"][$i] != "\0")

It looks like you're trying to treat the string as a C-style string. That
won't work in PHP because PHP's strings are not null-terminated. Thus,
this will lead to an infinite loop with any strings that don't happen to
have the null character somewhere within (and most strings won't).

>{
>if($_POST["username"][$i] == "." ||  $_POST["username"][$i] == "..")

This line is not wrong per-se, but nor does it entirely make sense. When
you access a string as an array, each element contains one character.
Here, you're checking whether each character in turn is a period (fine) or
two periods (makes no sense, since one character cannot represent two
period characters). What you'd probably want to do is simply remove the
second condition, since a check for one period will work just as well if
the name contains two periods. That is:

   if($_POST["username"][$i] == ".")

Incidentally, another tip: when comparing against a constant, as you are
in both your while() and your if(), place the constant on the left side if
the expression rather than the right. That is, write the previous if()
like this:

   if ('.' == $_POST['username'])

It might look a little funny, but I assure you, someday, it'll save you a
bunch of frustrating debugging time. The reason is that if you mistype the
'==' as '=', you'll do an assignment, the value of which is then returned.
This has the net effect of 1) quietly changing your variable's value, and
2) making the overall expression always evaluate to true, sending you into
the the true part of the conditional branch, well, unconditionally.



--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/








Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread George Langley

On 2011-09-22, at 11:53 AM, Mike Hansen wrote:

> Does anyone know of a site that has an online test of PHP skills? I'd like to 
> review my PHP knowledge.
> 
> I've already run across this site: 
> http://vladalexa.com/scripts/php/test/test_php_skill.html

Doesn't appear to be working. Just has a link to some blog and no 
results.

George


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



Re: [PHP] What determines your use of the type of DB framework/abstract?

2011-09-22 Thread Jamie Krasnoo
Sorry, not sure if the first part of the conversation made it to the list.

I will be looking in to Symfony. I'm well versed with ZF and Zend_Db.
I'm also somewhat versed with Doctrine and integrating it with ZF. My
question isn't whether Doctrine is a part *of* that framework but
rather on *what* and *when* it is appropriate to *use* or *substitute*
something like Doctrine instead of using straight pdo or mysqli or the
abstract that came with that particular framework. Substituting
Doctrine or some other abstract could complicate a project rather than
help.

Jamie

On Thu, Sep 22, 2011 at 10:52 AM, Slith  wrote:
> Have you looked into other PHP Frameworks like Symfony that includes
> Doctrine support?
>
> Not sure exactly what your requirements are but most PHP frameworks include
> some sort of DB abstraction based on Active Record/ORM.
>
> See also CodeIgniter, Zend Framework
>
> On 9/22/2011 10:46 AM, Jamie Krasnoo wrote:
>>
>> Hey All,
>>
>> I'm guessing that the subject probably doesn't fit the question I'm
>> asking here so I'll apologize in advance.
>>
>> Lately I've been getting in to how I can streamline my development
>> after a bad experience with a contract. One of the areas I was looking
>> at is when it would be appropriate to use certain DB frameworks? What
>> I mean by frameworks is probably more like DB abstract, like Doctrine
>> or ZF's native Zend_Db. I know this isn't a black and white
>> explanation so I would like to know what influences your decision on
>> using a DB abstract framework. Whether to use one or not and if so
>> which one?
>>
>> Jamie
>>
>
>

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



Re: [PHP] Re:

2011-09-22 Thread Tommy Pham
On Thu, Sep 22, 2011 at 9:25 AM, Eric  wrote:

> Thanks Very much I used,
> preg_match('/[[:punct:]]/', $_POST['username']) !== 0
> and it works without errors. The reason I can't just use
> is_file which I wish I could is because windows doesn't allow question
> marks
> or some wierd character. It decides to not allow php to make the file if
> there
> are odd  ball characters. It is a very unfortunate mistake in my code that
> I
> wish php would ignore and just make the file "?".


To prevent possible future warnings and errors use:

if (isset($_POST['username']) && preg_match('/[[:punct:]]/',
$_POST['username']) !== 0)


[PHP] Any free online tests to test my PHP knowledge?

2011-09-22 Thread Mike Hansen
Does anyone know of a site that has an online test of PHP skills? I'd 
like to review my PHP knowledge.


I've already run across this site: 
http://vladalexa.com/scripts/php/test/test_php_skill.html


Thanks,

Mike

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



[PHP] What determines your use of the type of DB framework/abstract?

2011-09-22 Thread Jamie Krasnoo
Hey All,

I'm guessing that the subject probably doesn't fit the question I'm
asking here so I'll apologize in advance.

Lately I've been getting in to how I can streamline my development
after a bad experience with a contract. One of the areas I was looking
at is when it would be appropriate to use certain DB frameworks? What
I mean by frameworks is probably more like DB abstract, like Doctrine
or ZF's native Zend_Db. I know this isn't a black and white
explanation so I would like to know what influences your decision on
using a DB abstract framework. Whether to use one or not and if so
which one?

Jamie

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



Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Nilesh Govindarajan
On 09/22/2011 10:36 PM, Robert Williams wrote:
> As an alternative to the regular expression approaches already provided by
> others, you could also use ctype_alnum():
> 
> if (ctyp_alnum($_POST['username'])) {
>//username contains only letters and numbers
> } else {
>//username contains characters other than letters and numbers
> } //if-else
> 
> Docs: 
> 
> 
> As a bonus, this will likely be quite a bit quicker than the regex-based
> approaches. That said, you'd have to be making many calls (e.g., inside a
> loop) for the difference to reach the point of being noticeable. For
> something like a one-time validation on page-load, use whichever you find
> most comfortable.
> 
> In your original question, you also mentioned looping through a variable
> to check for non-alphanumeric characters. The regex approach or the
> approach I outlined above is much better in this case, but as a learning
> exercise, you could do the looping like this:
> 
> $validCharacters = array('a', 'e', 'i', 'o', 'u');
> for ($i = 0; $i < count($_POST['username']); $i++) {
>if (in_array($_POST['username'][$i], $validCharacters)) {
>   echo 'Pass!';
>   } else {
>   echo 'Fail!';
>} //if-else
> } //for i
> 
> The key thing to note there is that you can treat the string like it's an
> array to loop through it. For more information about this, go here:
> 
> 
> 
> and search the page for the phrase "String access and modification by
> character".
> 
> 

And if you want to go the loop way, you could use range() to fill values
in $validCharacters.
$validCharacters = array_merge(range('A', 'Z'), range('a', 'z'));


-- 
Nilesh Govindarajan
http://nileshgr.com

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



[PHP] PHP process 32 v 64 bit virtual memory

2011-09-22 Thread James
Looking for some explanation (and verification) as to why the virtual memory 
increases by 5 fold (at the minimum) from 32 bit to 64 systems. I'm aware (for 
the most part) of the int, struct, etc changes from 32 to 64 bit. Results from 
running `php -r 'sleep(1000);' &` on 32 and 64 bit systems are below. PHP was 
built by hand.


32 bit
System => Linux kronos 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43 EDT 
2010 i686
Build Date => Sep 22 2011 08:50:40
Configure Command =>  './configure'  '--prefix=/opt/php'

Test: php -r 'sleep(1000);' &
root  4863  0.0  0.1   7064  1064 ?Ss   08:21   0:00 
/usr/sbin/sshd
root  5403  0.0  1.0  17736 11048 ?Ss   08:28   0:00  
\_ sshd: root@pts/1
root  5418  0.0  0.1   4540  1488 pts/1Ss   08:28   0:00
  \_ -bash
root  2340  0.0  0.3  13240  3288 pts/1S08:53   0:00
  \_ /opt/php/bin/php -r sleep(1000);
root  2341  0.0  0.0   4224   872 pts/1R+   08:53   0:00
  \_ ps axuf

64 bit
System => Linux ceous 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 
2010 x86_64
Build Date => Sep 22 2011 08:51:02
Configure Command =>  './configure'  '--prefix=/opt/php'

Test: php -r 'sleep(1000);' &
root  5181  0.0  0.1  62608  1220 ?Ss   08:22   0:00 
/usr/sbin/sshd
root  5724  0.0  1.5 102020 15620 ?Ss   08:27   0:00  
\_ sshd: root@pts/1
root  5726  0.0  0.1  66064  1608 pts/1Ss   08:28   0:00
  \_ -bash
root  2019  0.0  0.4  88864  4200 pts/1S08:54   0:00
  \_ /opt/php/bin/php -r sleep(1000);
root  2021  0.0  0.0  65592   924 pts/1R+   08:54   0:00
  \_ ps axuf


32 v. 64 virtual memory difference: 75624


Thanks!


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



Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Robert Williams
As an alternative to the regular expression approaches already provided by
others, you could also use ctype_alnum():

if (ctyp_alnum($_POST['username'])) {
   //username contains only letters and numbers
} else {
   //username contains characters other than letters and numbers
} //if-else

Docs: 


As a bonus, this will likely be quite a bit quicker than the regex-based
approaches. That said, you'd have to be making many calls (e.g., inside a
loop) for the difference to reach the point of being noticeable. For
something like a one-time validation on page-load, use whichever you find
most comfortable.

In your original question, you also mentioned looping through a variable
to check for non-alphanumeric characters. The regex approach or the
approach I outlined above is much better in this case, but as a learning
exercise, you could do the looping like this:

$validCharacters = array('a', 'e', 'i', 'o', 'u');
for ($i = 0; $i < count($_POST['username']); $i++) {
   if (in_array($_POST['username'][$i], $validCharacters)) {
  echo 'Pass!';
  } else {
  echo 'Fail!';
   } //if-else
} //for i

The key thing to note there is that you can treat the string like it's an
array to loop through it. For more information about this, go here:



and search the page for the phrase "String access and modification by
character".







Regards,

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/


Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

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



Re: [PHP] Re:

2011-09-22 Thread Igor Escobar
No problem ;)


Regards,
Igor Escobar
*Software Engineer
*
+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar 





On Thu, Sep 22, 2011 at 1:25 PM, Eric  wrote:

> Thanks Very much I used,
> preg_match('/[[:punct:]]/', $_POST['username']) !== 0
> and it works without errors. The reason I can't just use
> is_file which I wish I could is because windows doesn't allow question
> marks
> or some wierd character. It decides to not allow php to make the file if
> there
> are odd  ball characters. It is a very unfortunate mistake in my code that
> I
> wish php would ignore and just make the file "?".


Re: [PHP] RE: How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Nilesh Govindarajan
On 09/22/2011 09:24 PM, Eric wrote:
> if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
> echo "";
> echo "Username must only contain A-Z and 0-9";
> include("register.html");
> exit;
> }
> 
> I used the code above but I now get this error message
> 
> Warning: preg_match() [function.preg-match]: Unknown modifier '^' in 
> C:\Documents and 
> Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\forum\register.php on line 2
> 
> I don't like to run php with errors off so I wanna ask how I can fix this.

Oh damn, I just forgot that the pattern is to be enclosed between
delimiters. Glad that you found the fix using ctype_alnum though. A new
learning for me.

-- 
Nilesh Govindarajan
http://nileshgr.com

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



[PHP] Re:

2011-09-22 Thread Eric
Thanks Very much I used,
preg_match('/[[:punct:]]/', $_POST['username']) !== 0
and it works without errors. The reason I can't just use
is_file which I wish I could is because windows doesn't allow question marks
or some wierd character. It decides to not allow php to make the file if there
are odd  ball characters. It is a very unfortunate mistake in my code that I
wish php would ignore and just make the file "?".

[PHP] Re: How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Shawn McKenzie
On 09/22/2011 10:54 AM, Eric wrote:
> if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
> echo "";
> echo "Username must only contain A-Z and 0-9";
> include("register.html");
> exit;
> }
> 
> I used the code above but I now get this error message
> 
> Warning: preg_match() [function.preg-match]: Unknown modifier '^' in 
> C:\Documents and 
> Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\forum\register.php on line 2
> 
> I don't like to run php with errors off so I wanna ask how I can fix this.

if(!ctype_alnum($_POST['username'])) {
   // is not alpha numeric
}

-- 
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] RE: How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Marco Lanzotti
Il 22/09/2011 17:54, Eric ha scritto:
> if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {

Whi this '(.*)'?

For '.' and '..' problem use is_file().

Bye,
Marco

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



Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Igor Escobar
Or...  just use:

if(preg_match('/^[A-Za-z0-9]+$/', $_POST['username']) !== 0) {
// string contains other characters, write the code
}

You can see this regex in action here: http://regexpal.com/?flags=®ex=
^%5BA-Za-z0-9%5D%2B%24&input=myusername01

If you put anything different of A-Za-z0-9 the regex will not match.

Regards,
Igor Escobar
*Software Engineer
*
+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar 





On Thu, Sep 22, 2011 at 10:03 AM, Igor Escobar wrote:

> Use this regex:
> if(preg_match('/[[:punct:]]/', $_POST['username']) !== 0) {
>
> // string contains other characters, write the code
> }
>
> The POSIX class [:punct:] means matches any punctuation and symbols in
> your string and that includes [!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]
>
>
> Regards,
> Igor Escobar
> *Software Engineer
> *
> + http://blog.igorescobar.com
> + http://www.igorescobar.com
> + @igorescobar 
>
>
>
>
>
>
> On Thu, Sep 22, 2011 at 9:17 AM, Nilesh Govindarajan  > wrote:
>
>> On Thu 22 Sep 2011 08:25:29 PM IST, Eric wrote:
>> > I have this problem when using php because my computer recognizes
>> > the characters "." and ".." as an existing file when I use file_exists.
>> Also
>> > I want to check $_POST["username"] for characters other then A-Z a-z and
>> 0-9.
>> > If it contains anything other then, I would like to prompt the user but
>> > I can't seam to use foreach properly and I don't know how to itterate
>> > through the post variable with a for loop while loop or do while loop.
>>
>> file_exists() for . and .. would always return true, because they
>> really exist! . is an alias for the current directory and .. for the
>> parent directory. This is irrespective of OS.
>>
>> To search $_POST["username"] for characters other than A-Z, a-z, 0-9,
>> you can use preg_match something like this (there's an alpha class as
>> well, but I'm not sure about it):
>>
>> if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
>> // string contains other characters, write the code
>> }
>>
>> --
>> Nilesh Govindarajan
>> http://nileshgr.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>


Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Igor Escobar
Use this regex:
if(preg_match('/[[:punct:]]/', $_POST['username']) !== 0) {
// string contains other characters, write the code
}

The POSIX class [:punct:] means matches any punctuation and symbols in your
string and that includes [!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]


Regards,
Igor Escobar
*Software Engineer
*
+ http://blog.igorescobar.com
+ http://www.igorescobar.com
+ @igorescobar 





On Thu, Sep 22, 2011 at 9:17 AM, Nilesh Govindarajan
wrote:

> On Thu 22 Sep 2011 08:25:29 PM IST, Eric wrote:
> > I have this problem when using php because my computer recognizes
> > the characters "." and ".." as an existing file when I use file_exists.
> Also
> > I want to check $_POST["username"] for characters other then A-Z a-z and
> 0-9.
> > If it contains anything other then, I would like to prompt the user but
> > I can't seam to use foreach properly and I don't know how to itterate
> > through the post variable with a for loop while loop or do while loop.
>
> file_exists() for . and .. would always return true, because they
> really exist! . is an alias for the current directory and .. for the
> parent directory. This is irrespective of OS.
>
> To search $_POST["username"] for characters other than A-Z, a-z, 0-9,
> you can use preg_match something like this (there's an alpha class as
> well, but I'm not sure about it):
>
> if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
> // string contains other characters, write the code
> }
>
> --
> Nilesh Govindarajan
> http://nileshgr.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP] RE: How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Eric
if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
echo "";
echo "Username must only contain A-Z and 0-9";
include("register.html");
exit;
}

I used the code above but I now get this error message

Warning: preg_match() [function.preg-match]: Unknown modifier '^' in 
C:\Documents and 
Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\forum\register.php on line 2

I don't like to run php with errors off so I wanna ask how I can fix this.

Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Tommy Pham
On Thu, Sep 22, 2011 at 7:55 AM, Eric  wrote:

> I have this problem when using php because my computer recognizes
> the characters "." and ".." as an existing file when I use file_exists.
> Also
> I want to check $_POST["username"] for characters other then A-Z a-z and
> 0-9.
> If it contains anything other then, I would like to prompt the user but
> I can't seam to use foreach properly and I don't know how to itterate
> through the post variable with a for loop while loop or do while loop.


$pattern = '/^[A-Za-z0-9]/';
/* http://php.net/control-structures.foreach */
foreach ($_POST as $key => $value)
{
/* http://php.net/function.preg-match */
  if (preg_match($pattern, $value) > 0)
  {
  /* prompt user */
  }
}


Re: [PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Nilesh Govindarajan
On Thu 22 Sep 2011 08:25:29 PM IST, Eric wrote:
> I have this problem when using php because my computer recognizes
> the characters "." and ".." as an existing file when I use file_exists. Also
> I want to check $_POST["username"] for characters other then A-Z a-z and 0-9.
> If it contains anything other then, I would like to prompt the user but
> I can't seam to use foreach properly and I don't know how to itterate
> through the post variable with a for loop while loop or do while loop.

file_exists() for . and .. would always return true, because they
really exist! . is an alias for the current directory and .. for the
parent directory. This is irrespective of OS.

To search $_POST["username"] for characters other than A-Z, a-z, 0-9,
you can use preg_match something like this (there's an alpha class as
well, but I'm not sure about it):

if(preg_match('(.*)^[A-Za-z0-9]+', $_POST['username']) !== 0) {
// string contains other characters, write the code
}

-- 
Nilesh Govindarajan
http://nileshgr.com

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



[PHP] How can I check for characters in a $_POST[] variable?

2011-09-22 Thread Eric
I have this problem when using php because my computer recognizes
the characters "." and ".." as an existing file when I use file_exists. Also
I want to check $_POST["username"] for characters other then A-Z a-z and 0-9.
If it contains anything other then, I would like to prompt the user but
I can't seam to use foreach properly and I don't know how to itterate
through the post variable with a for loop while loop or do while loop.