SitePoint Sponsor

User Tag List

Page 1 of 9 12345 ... LastLast
Results 1 to 25 of 219

Thread: PHP Quiz

  1. #1
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Quiz

    Hey everyone,

    How about a little quiz? I'll post a question and if you can answer it correctly you can post your own PHP question

    Try to answer the question without just running the code

    PHP Code:
    <?php

        $i 
    'Z';

        echo ++
    $i;

    ?>
    Question 1. What will the above code output?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    It prints AA. Come on give me something hard

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by seanf
    Try to answer the question without just running the code







    Only joking! Where's your question?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    haha

    hmmm... I gotta think of a good one.

  5. #5
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well now he said AA, and everyone knows... ok the answer is AA, can i ask a question now?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  6. #6
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cyborg from dh
    well now he said AA, and everyone knows... ok the answer is AA, can i ask a question now?
    You can post a question in my place... I can't come up with anything good.

  7. #7
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, wait for Stephan! Let's hope he comes up with something soon!

    [EDIT] He wimped out!

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  8. #8
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok give me a few minutes here.. I'll think of something...
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  9. #9
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm going to bed. Night all

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  10. #10
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dang, this is harder than I thought it would be.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  11. #11
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about a question i actually need answered:

    i need a regex to match any numerical number, (including a decimal)

    (trying not to make it too hard )
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  12. #12
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By decimal, you mean full-stop, right?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  13. #13
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    #[0-9]{1,M}\.[0-9]{1,N}#
    Where M is the maximum number of digits before the decimal point and N the number of decimals.

  14. #14
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need it to match any length of numbers before the decimal, and any length after, as well as not requiring the decimal.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  15. #15
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    done
    Code:
    #^[0-9]+(\.[0-9]+)?$#
    Paul [edit]Fixed minor error

  16. #16
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good work, you win.

    (That one was way too easy, but I couldn't think of anything, lol)
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  17. #17
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, my turn.
    This one is mysql & php:
    you got 3 tables

    table1
    -------------------------------
    ID name

    table2
    ------------------------------
    ID filename TypeID

    table3
    ---------------------------
    ID type

    The chanllenge is make a query to fetch the following fields, table1.ID, name, filename and type and store them into a new table

    newtable
    -----------------
    ID (must same as table1.id)
    name
    fliename
    type

    NOTE: TypeID could be NULL.

    Good Luck

  18. #18
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you didn't say how the tables are related so i will assume that table2.TypeID references table3.ID and table1.ID references table2.ID (???).

    no PHP needed, just 1 query:

    Code:
    CREATE TABLE newtable (
    	ID SMALLINT UNSIGNED NOT NULL,
    	name VARCHAR(64) NOT NULL,
    	filename VARCHAR(64) NOT NULL,
    	type VARCHAR(16),
    	PRIMARY KEY (ID)
    ) SELECT t1.ID, t1.name, t2.filename, t3.type FROM table1 t1, table2 t2
    	LEFT JOIN table3 t3 ON (t3.ID=t2.TypeID)
    	WHERE t2.ID=t1.ID
    	ORDER BY t1.ID;
    is that right...?
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  19. #19
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $query mysql_query("SELECT
    table1.ID,
    table1.name,
    table2.filename,
    table2.TypeID,
    table3.type
    FROM
    table1,table2,table3
    WHERE (table1.ID=table2.ID AND table2.ID=table3.ID);"
    );
    while (
    $result mysql_fetch_array($query))
    {
        
    $result['ID'] = (int) $result['ID'];
        
    $result['name'] = addslashes($result['name']);
        
    $result['filename'] = addslashes($result['filename']);
        
    $result['type'] = addslashes($result['type']);
        
    mysql_query("INSERT INTO newtable (ID, name, filename, type) VALUES
                    (
    $result[ID], '$result[name]', '$result[filename]', '$result[type]');");

    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  20. #20
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TypeID is never used in the new table...
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  21. #21
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Edit:

    That's right, TypeID is not used.
    Actually Type ID is not needed in the new table.



    Let me check the code ...
    Last edited by Paul S; Apr 3, 2003 at 20:26.

  22. #22
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! All would share my opinion, due easiness, Matt is the winner, your turn.

    (I love when you can reduce all your problems to a single line of code. )

  23. #23
    SitePoint Zealot Anagram's Avatar
    Join Date
    Feb 2003
    Location
    Norway
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hmm, can I ask one? :)

    If I may ask one, let's try this then:

    Ok, it's not that hard at all, just to test you guys


    What does this do?

    <?PHP echo $HTTP_SERVER_VARS["REMOTE_ADDR"]; ?>
    If pigs could fly, the prize of bacon would reach the sky.

    www.dosspirit.net - Norwegian
    reviews of DOS games

  24. #24
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo's the remote ip address of the user accessing the script, unless it is the isp, in which case, usually, HTTP_X_FORWARDED_FOR is set.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  25. #25
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Paul S
    Great! All would share my opinion, due easiness, Matt is the winner, your turn.

    (I love when you can reduce all your problems to a single line of code. [img]images/smilies/biggrin.gif[/img] )
    question... who's matt?

    (i just didn't see anyone names matt post... i might not know some names though )
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.


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
  •