Forum Moderators: coopster

Message Too Old, No Replies

explanation of a line of code

         

humpingdan

4:13 pm on Mar 26, 2004 (gmt 0)

10+ Year Member



}
while ( $row = mysql_fetch_array($result) ) {
$linkid = $row['id'];
$linktitle = $row['title'];
$linkurl = $row['link'];

echo('<p>'.'<a href="' . $linkurl . '">' . $linktitle . '</a>'.'</p>');

}

just the one line i dont quite get, i know what it does but why its strutured that way i dont know?

echo('<p>' (i understand)

. (i dont understand)

'<a href="' (i understand)

. $linkurl . ' (i dont understand)

in short i dont really understand the need for the "."'s
why do i have to put a "." in between statements,
im sure its plainly obvious!

Thanks

HelenDev

4:30 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



. is where you concatenate strings and variables in php

like + does in javascript

'<p>my html stuff</p>'.$myvariable.'<b>some more html</b>

Timotheos

4:57 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in short i dont really understand the need for the "."'s
why do i have to put a "." in between statements

This is a very strange structure and you don't need to do it. See the manual on string types. [php.net]

jatar_k

7:02 pm on Mar 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that could also be written like so

echo "<p><a href=\"$linkurl\">$linktitle</a></p>";

only difference being that it is enclosed by double quotes meaning that variables inside will be evaluated. We then also need to escape (precede with \) all double quotes contained within the string to be echo'ed