SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, just a simple question:


    If I have a function:

    function Split($SiteName){
    explode (".", $SiteName)
    echo $SiteName[0];
    }

    and I want to pass a string to it by value, what is the correct syntax:

    split(somesitename.com);
    or
    split("somesitename.com");

    or does it matter?

    Dumb and basic QU I know!

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    split("somesitename.com");

    This is correct. Here you are passing a string literal.
    You can also pass a string by variable:

    $url = "somesitename.com";
    split($url);

    - I know you already know this

    BTW did you notice that you declared the function with this signature:
    function Split($SiteName)
    but called it like so:
    split("somesitename.com");

    I've read that function names in PHP are not case sensitive -
    so that should be ok to do in PHP. However, it is a bad habbit to
    slip into (ignoring case in function names) because in most
    programming languages function names are case sensitive.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for the answer.

    The "caps error" was just a typo, but cheers anyway.

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm confused - wouldn't creating a function called split() produce an error, since it's already bulit-into the language? In that case, Split() would actually be the way to go.


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
  •