Page 1 of 1

confusing href tag with php....

Posted: Wed Nov 02, 2005 12:26 am
by Sequalit

Code: Select all

<A href=\"dblist.php?", $tablename, "\">", $tablename, "</A>
Ive done some googling to see what this means, but i cant seem to find it...

first confusing thing is that backslash... i dont get that, then you have the normal quotes

then a comma and a php variable ??? whats that, then another comma and another backslash in quoates!!!...

along with more quotes and some comma's, this is very confusing to me!!!

Posted: Wed Nov 02, 2005 12:38 am
by AGISB
Ok that is easy:

The backslash is called escaping. You need to escape special chars so the interpreter can understand what you want.

e.g.

Code: Select all

$var = "<a href="index.php">Link</a>";
can't work as expected as php wouzld consider the second " as string end.

You use the \

Code: Select all

$var = "<a href=\"index.php\">Link</a>";
and it works like intended


I have personally not used commas but points but the effect is the same.

Code: Select all

$var = "<A href=\"dblist.php?", $tablename, "\">", $tablename, "</A>";
It simply lines strings together to 1 string. However in that case above it is unnesessary.

Code: Select all

$var = "<A href=\"dblist.php?$tablename\">$tablename</A>";
would do the same as variables execute within "".


To complicate the matter you can use ' ' to outline strings and I actually would recommend it. It seems more complicated at first but it can avoid errors later. Between ' ' you don't need to escape chars exept \ and '.

Code: Select all

$var = '<A href="dblist.php?'.$tablename.'">'.$tablename.'</A>"';
would output the same as above. You need to move the variables out of the ' ' because they don't execute there.

Posted: Wed Nov 02, 2005 7:27 am
by feyd
the code was intended to be given to echo, as it allows the data sent to it to be separated by commas..