Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    187
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Exclamation Basic string question

    Hey all i am new at PHP so be nice

    How can i do the following code in php?
    Code:
    <%
    dim strName
    dim strTheName
    
    strTheName = "BOB"
    
    strName = "Welcome " & strTheName & " to your site!"
    response.write strName
    %>
    I've tried this:
    Code:
    $user_id_name = "BOB";
    
    $html = 'Welcome ' & $user_id_name & ' to your site!"';
    echo $html;
    But that doesnt seem to display anything for the $user_id_name. just the Welcome and the to your site!.

    Any help would be great!
    David

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Location
    AZ, USA
    Posts
    685
    Thanks
    6
    Thanked 46 Times in 46 Posts
    Almost, it should be

    PHP Code:
    $user_id_name "BOB";

    $html 'Welcome ' $user_id_name ' to your site!';
    echo 
    $html
    A dot ( . ) is the php equivalent of the asp ampersand ( & ) in this situation.

  • #3
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    187
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Yep that did it binaryWeapon.

    Thanks for the knowledge!

    David

  • #4
    New Coder
    Join Date
    Jul 2007
    Location
    Colorado, USA
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    While the . is the string join function, a better way to accomplish this example would be:

    Code:
    $user_id_name = 'BOB';
    
    echo 'Welcome ', $user_id_name, ' to your site!"';
    Unless you really need the string stored as a variable, using echo with commas to separate the parts is faster and better. It will work with the string . to join the parts, but isn't as fast.

    Also, the declaration of $user_id_name should be in single quotes, not double as you don't need to have PHP parse any variables inside. It will be faster as well.

    Just a few tips to help you out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •