Jump to content

Archived

This topic is now archived and is closed to further replies.

OriginalSunny

Links in php

Recommended Posts

Any1 know why this link doesnt work in php??

[i]echo "<a href="menu.htm" target="mainwindow">Return to main menu</a><br><br>";[/i]

Its simply html code which is echoed so shouldnt it work?

Share this post


Link to post
Share on other sites
Because your are not escaping your (double) quotes.

You start your echo statement with a double quote then you start to assign a html attribute in the anchor tag (whi h is href) and you start you assign a value to this attrubute using a double quote. So PHP assumes you are ending the echo statement and so you get an unexpected result. All you need to do in order to resolve this is by adding a backslash to your double quotes like so:
[code]echo "<a href=\"menu.htm\" target=\"mainwindow\">Return to main menu</a><br><br>";[/code]

Also the same principle applies with single quotes too.

Share this post


Link to post
Share on other sites
[code]
echo "<a href=\"menu.html\" target=\"mainwindow\">Return to main menu</a><br><br>"[/code]

php sees the double quotes of the href and target tag as part of php, by adding the slashes before it, were telling php to read it as html. Also, its been a while since ive specified where i want a window to open, but it mainwindow really a valid target? plus, if the page is on your site, you shouldnt need to specify a target

edit:
damn.. i always get beaten to these questions.. 1 minute before i posted.. damn

Share this post


Link to post
Share on other sites
I absolutely hate seeing escaped quotes in a PHP source, since it makes the source so hard to read. and there are many ways to aviod using them. In this case just replace the first and last doube quotes with single quotes.
[code]<?php echo '<a href="menu.htm" target="mainwindow">Return to main menu</a><br><br>'; ?>[/code]

And now you have a syntacally correct "echo" statement that is easy on the eyes.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.