Page 2 of 2 First 12
  • Jump to page:
  1. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Hartford, WI
    Rep Power
    Ah, ok. Maybe I haven't gotten in the habit of such, because when I have variables within a line, I do something similar to:

    PHP Code:
    $var "Good afternoon, " $name " and welcome to our site!"
    Is that ok? Or is one way prefered over the other? And I do apologize again, newbie1234. for stepping in like this. :-/
  2. #17
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    Originally Posted by Triple_Nothing
    Is that ok?
    That's the general solution. Inserting variables directly into strings is limited to special cases which don't require escaping or allow you to escape the whole string at once.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #18
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    Either way is fine, yes. If your variables require escaping, you can do it before the fact and use string interpolation, or do it inline using your method.

    It's actually faster to echo a series of strings and variables using COMMAS, rather than concatenation:

    PHP Code:
    echo 'Good afternoon, '$name' and welcome to our site!'
    Note that I changed your double-quotes to single (very slightly faster) and your periods to commas (very slightly faster).

    Edit: When I said echo, I mean it. Echo is the only place this syntax works. /EDIT

    Don't worry about stepping on newbie's toes, her homework was due yesterday, so if she still doesn't have it done she's going to have to deal with her professor, not us.
    Last edited by ManiacDan; March 1st, 2013 at 11:00 AM.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo