Jump to content

Links in php


OriginalSunny

Recommended Posts

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.
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.