Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: OO PHP slashes

  1. #1
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Hey guys, i have this script from the book (i'm gettin' my learn on ya know)...

    PHP Code:

        
    public function DisplayKeywords();
        {
            echo 
    '<meta name= \ "keywords\" content=\ "".htmlentities($this->keywords). "\" />';
        } 
    Can someone tell me what the slashes do ( \ ). I'm just not quite sure. I understand what the code does... but the slashes ( \ ) just bewilder me! :ermm:

  2.  

  3. #2
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Well, in your case you've got some errors. You should have echo using double quotes ("). A slash escapes the quote so as not to end the string.

    PHP Code:
    echo "testing " "this" " here"// returns testing this here
    echo "testing \"this\" here"// returns testing "this" here 
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  4. #3
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    AHHH OK! I get. I should be using double quotes than to make it read as a string right?

  5. #4
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Well, if you want the \" to act as expected. There's two ways to do what you're looking for above. In single-quoted strings, you only need to escape single quotes. In double-quoted strings, you need to escape double quotes.

    PHP Code:
    echo '<meta name="keywords" content="' htmlentities($this->keywords) . '" />';
    echo 
    "<meta name= \"keywords\" content=\"" htmlentities($this->keywords) . "\" />"
    I'd personally go with the first option since it's easier to read. But, it's all up to personal style.
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  6. #5
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    well, i thought about that... and was wondering what this guys is writing.... what's the point of the 2nd method than. I like the 1st a lot better!!!

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Off-topic - typical naming conventions for OO are as follows:

    Microsoft:

    ClassName
    MethodName()
    ParameterName

    Java:

    ClassName
    methodName()
    parameterName

    PHP:

    ClassName
    methodName() or method_name()
    parameterName ro parameter_name

    My preference for PHP:

    ClassName
    methodName()
    parameter_name

  8. #7
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    According to your post smosely I am a Java developer... nooooo!

  9. #8
    Senior Member Eddy Bones's Avatar
    Join Date
    Jan 2004
    Location
    Washington, USA
    Posts
    1,054
    Member #
    4651
    According to his post I am a Java developer, too. Oh, wait, ColdFusion is Java. Coooool.

  10. #9
    Senior Member Tomaszewski's Avatar
    Join Date
    Oct 2006
    Location
    Exton, PA
    Posts
    194
    Member #
    14132
    Quote Originally Posted by smoseley
    Off-topic - typical naming conventions for OO are as follows:

    Microsoft:

    ClassName
    MethodName()
    ParameterName

    Java:

    ClassName
    methodName()
    parameterName

    PHP:

    ClassName
    methodName() or method_name()
    parameterName ro parameter_name

    My preference for PHP:

    ClassName
    methodName()
    parameter_name
    By naming conventions you mean, we as the developers choose our naming convention and based on your experience, in PHP, we (should) use:


    ClassName
    methodName() or method_name()
    parameterName or parameter_name

    did I get that right?

  11. #10
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Right, though organizations will often publish standards for naming conventions, as the ones I showed above.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:11 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2022 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com