SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have a form, where someone enters emails into a text area, each email is on a separate line.

    Could anyone tell me how I would loop through these setting these fields aswell:

    date=CURDATE()
    valid='1'

    These must be entered into a table called emails.
    I'm just having trouble getting it to get a separate entry on every line and looping it to insert it into the database.

    Also wondering, instead of using hundreds of queries for this one, is it possible to only use 1 query that inserts them all?

    Thank you

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Ignore this post, I spent the last few hours at php.net and found split() which worked.

    Thanks

  3. #3
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explode() will do what you want too..

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Monmouth Junction, NJ
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well id still prefer explode over split

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which is better?

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explode() is faster unless you need the added functionality of regular expressions, then you need to use split().

    Kind of the same as ereg_replace() vs. str_replace()
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks freddy

    Adding to this post:
    What would the best regular expression to use to check that an email address is a valid one?

    P.S In my next post you'll notice some code, do you recognise it? You wrote it for me about two weeks ago.

    Thanks
    Peter

  8. #8
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Peter

    This is what I've used for email address checking --

    PHP Code:
            if ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2}[mtgvu]?$"$ReplyToAddress) )
    {
       
    // email is ok

    of course, I don't know if it's the best or not

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does that check the email address for?

  10. #10
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have been using

    PHP Code:
    if (ereg ("^.+@.+\\..+$"$str)) {
    return 
    1;
    } else {
    return 
    0;
     }

    but no idea what the difference between them is...

  11. #11
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From my understanding of regular expressions, my pattern checks the following:

    ^[_a-z0-9-]+ The string begins with one or more characters a-z, 0-9, underscores and hyphens

    (.[_a-z0-9-]+)* and is followed by zero or more occurances of a dot followed by some characters again (sometimes people have some.name@address.com, and we want to allow the period between some and name, but not two periods in a row).

    @ followed by the @ sign

    ([0-9a-z][0-9a-z-]*[0-9a-z].)+ followed by one or more of the combination of (1) a letter/number, (2) zero or more letters/numbers/hyphens, (3) a letter/number and (4) a period.

    [a-z]{2}[mtgvu]?$ and the string ends with two letters (and if it has a third letter, it has to be one of "mtgvu" (as in .com, .gov etc).

    -----------

    Padders, your expression checks that the string begins with one or more characters (any character) followed by the @ sign, followed by one or more characters, followed by a period which is followed by one or more characters (the last set of characters would typically be the .com, .org etc...)

  12. #12
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Did you think of names like com.au (australia)
    co.uk (uk)
    .ir (ireland)

  13. #13
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those would be fine because the com (from com.au) and co (from co.uk) would get picked up by the first regex after the @ sign, and the .au/uk/ir would get picked up by the last part of the regex -- the [a-z]{2} means that the last part has to have any two letters and the [mtgvu]? means that it can have a third letter, but if there is the third letter, it has to be one of those five letters.

  14. #14
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks like i am swapping expressions then, yours is more powerful, thanks.

  15. #15
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So I guess I should hope my explanation is correct, eh?

    It all depends on what your needs are -- I'm sure there are more extreme regex's out there that can blow the one I posted away heh


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
  •