confusing href tag with php....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sequalit
Forum Commoner
Posts: 75
Joined: Wed Oct 12, 2005 9:57 pm
Location: Texas

confusing href tag with php....

Post 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!!!
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the code was intended to be given to echo, as it allows the data sent to it to be separated by commas..
Post Reply