Jump to content


Links in php

  • Please log in to reply
3 replies to this topic

#1 OriginalSunny

  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 09 March 2006 - 09:34 AM

Any1 know why this link doesnt work in php??

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

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

#2 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 March 2006 - 12:36 PM

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:
echo "<a href=\"menu.htm\" target=\"mainwindow\">Return to main menu</a><br><br>";

Also the same principle applies with single quotes too.

#3 insrtsnhere13

  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 09 March 2006 - 12:37 PM

echo "<a href=\"menu.html\" target=\"mainwindow\">Return to main menu</a><br><br>"

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

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

#4 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 March 2006 - 12:50 PM

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.
<?php echo '<a href="menu.htm" target="mainwindow">Return to main menu</a><br><br>'; ?>

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


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users