...

View Full Version : correct syntax



DJ Hands3
09-05-2009, 01:26 PM
Having trouble getting the correct syntax on this script to work example below,



$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

bacterozoid
09-05-2009, 01:35 PM
You can't use commas when building a string like that. Commas are only applicable when using echo.


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

Fou-Lu
09-05-2009, 11:17 PM
You can't use commas when building a string like that. Commas are only applicable when using echo.


$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:


$display_stream = sprintf('<li><a href="%s" title="%s">Stream</a></li>' . PHP_EOL, $link[1], $stream);

bacterozoid
09-05-2009, 11:43 PM
I've never thought to use that method in PHP - I only do it in C.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum