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

Thread: correct syntax

  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts

    correct syntax

    Having trouble getting the correct syntax on this script to work example below,

    PHP Code:
    $display_stream =  '<li><a href="'$link[1], '" title="'$stream'">Stream</a><br />'"\n";
                     
    //$display_stream = "<li><a href=$link[1] title=$stream />Stream</a><br />"; - working but only displays 1 url link rather than all links on page
                     //echo '<li><a href="', $link[1], '" title="', $stream, '">Stream</a><br />', "\n";  - original function 

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    You can't use commas when building a string like that. Commas are only applicable when using echo.

    PHP Code:
    $display_stream =  '<li><a href="' $link[1] . '" title="' $stream '">Stream</a><br />' "\n"

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by bacterozoid View Post
    You can't use commas when building a string like that. Commas are only applicable when using echo.

    PHP Code:
    $display_stream =  '<li><a href="' $link[1] . '" title="' $stream '">Stream</a><br />' "\n"
    That bugs me so much, I wish that it would be removed. I hate that the echo (and only echo), will accept multiple parameters.
    That said, I'm a print formatter, so I'd go with the sprintf route:
    PHP Code:
    $display_stream sprintf('<li><a href="%s" title="%s">Stream</a></li>' PHP_EOL$link[1], $stream); 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    I've never thought to use that method in PHP - I only do it in C.


  •  

    Posting Permissions

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