n00bish PHP question

Discussion in 'PHP' started by frostbite, Jun 29, 2007.

  1. #1
    Yeah, I'm really tired, How do I write a URL in PHP?

    $variable = (http://www.domain.com/index.php-forum-3.html)

    thats what my URL looks like. How do I write it so it works? I mean like adding backslashes and things.
     
    frostbite, Jun 29, 2007 IP
  2. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you just want to set it as a variable?

    $var = 'http://www.example.com/blah_blah_blah.html';

    Josh
     
    Acecool, Jun 29, 2007 IP
  3. UnrealEd

    UnrealEd Peon

    Messages:
    148
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what do you mean with "so it works"? if you want it to be clickable, you have to use proper html tags (<a href="..."></a>), if you just want to make a string with a url in it, then Acecool's solution will do fine.
     
    UnrealEd, Jun 30, 2007 IP
  4. Jikdor

    Jikdor Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Dont realy understand what your trying to do?

    $variable = "http://www.domain.com/index.php-forum-3.html";
    echo $variable;
     
    Jikdor, Jun 30, 2007 IP
  5. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Avoid double quotes where possible.. In small applications it wont matter, but if you create a large application it will slow down the script quite a bit.
     
    Acecool, Jun 30, 2007 IP
  6. amorph

    amorph Peon

    Messages:
    200
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yeah....with 0.00001 miliseconds
     
    amorph, Jun 30, 2007 IP
  7. CodyRo

    CodyRo Peon

    Messages:
    365
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It won't parse variables and just spit it out (echo '$var' will spit out $var, not whats in the variable).

    I think amorph hit the nail on the head..
     
    CodyRo, Jun 30, 2007 IP
  8. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Well someone took the time you actually find this out


    http://spindrop.us/2007/03/03/php-double-versus-single-quotes/


    It's some personal blog I ran into but it seems legit.

    The best part

    So Cody really summed up their real uses.
     
    InFloW, Jun 30, 2007 IP
  9. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    $var = "0";
    echo "$var"; echos 0

    echo '$var'; echos $var

    echo $var; echos 0 // BEST WAY
     
    Acecool, Jun 30, 2007 IP
  10. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #10
    there really is no "best" way to do it. it's all about choice. personally i like to concatenate strings around my variables for easy location within my editor. (different color) see example.

    
    $var = "variable";
    echo "this " .$var. " is being output to the screen.";
    
    PHP:
    vs


    
    $var = "variable";
    echo "this $var is being output to the screen.";
    
    PHP:
     
    ansi, Jun 30, 2007 IP
  11. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Using single quotes forces you to do just that, and it doenst have to even look at the stuff that is not ' . here . ' which helps for HUGE applications
     
    Acecool, Jun 30, 2007 IP
  12. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #12
    again, it's a matter of choice. single quotes or double, it really doesn't matter.
     
    ansi, Jun 30, 2007 IP