OriginalSunny Posted March 9, 2006 Share Posted March 9, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/4515-links-in-php/ Share on other sites More sharing options...
wildteen88 Posted March 9, 2006 Share Posted March 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4515-links-in-php/#findComment-15742 Share on other sites More sharing options...
insrtsnhere13 Posted March 9, 2006 Share Posted March 9, 2006 [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 targetedit:damn.. i always get beaten to these questions.. 1 minute before i posted.. damn Quote Link to comment https://forums.phpfreaks.com/topic/4515-links-in-php/#findComment-15743 Share on other sites More sharing options...
kenrbnsn Posted March 9, 2006 Share Posted March 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/4515-links-in-php/#findComment-15747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.