Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: PHP detect uppercase and length of the word

  1. #11
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    If ever you can script without using PCRE (Perl Compatible Regular Expressions) you should do so since PCRE uses a lot of processor resources. As I recall, Perl has an engine specifically designed for regex and is not processor heavy.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #12
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    It is done with this one... can someone take a look to this?? HERE

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    If the goal is to see if there are BOTH lowercase and uppercase, then using the two functions in my post above will work-- basically you're checking that it's already not all lowercase and not all uppercase.

    What you're doing could never return true, I believe. (Though I'm no good with regex either.)
    I see what you're doing now - yes, you're right. I was misreading the syntax.

    I think my solution would work as well, though I haven't tried it. I'll let you know.

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ah, and I think I was reading yours wrong.

    Does the function check for ANY matches or a complete match from the whole string?
    You're saying "exists [uppercase] and exists [lowercase]", not "[whole string is upper] and [whole string is lower]".

    I read it the second way when I first saw your post.


    In other words, preg_match returns TRUE upon finding a match, rather than returning FALSE upon finding a non-match.



    Yes, that would work, but personally I'd prefer the more "human readable" string functions (when they work, of course-- sometimes regex is needed/easier).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Exactly. [A-Z] is the character range we're searching for, and + means "one or more of".

    Using functions might be quicker, since regex can be more process-intensive, but with the (likely small) size of our $string, I don't think it would be an issue. I think it would improve the speed of the regex if I combined them into a single pattern, too, instead of checking twice.

  6. #16
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not sure you would be able to combine them together in the sense that you are checking if (1) and if (2), not if (1/2).
    My motivation for using string functions is simply that they are easier (for me). Regex likely is a bit slower, but using it can be more standardized if you are doing a lot of checks for lots of different patterns and it can also do a lot that string functions can't.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #17
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    this works. true for UPPER and lowercase, but not UPPER or lowercase:
    PHP Code:
    preg_match('/(?=.*[A-Z])(?=.*[a-z])/'$str

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •