PHP External Links

Hi,

I have a peice of code which publishes an image with a link from my database. However I cant get it to use external links. My code is:

echo "<a href=\\"" .$link . "\\"><img src=\\""   .$image ."\\" />  </a><BR />";

I have tried all the options I can think of but I cant get it work. Can anyone advise please?

Hi,

I dont understand why would there be an error?

Does it use target=“_blank”

I thought I would a php command to open the image link in a new page.

try this:


echo "<a href=\\"" .$link . "\\"><img src=\\""   .$image ."\\" />".$image. "</a><BR />"; 

or


echo "<a href=\\"" .$link . "\\"><img src=\\""   .$image ."\\" />click here</a><BR />"; 

Hi,

I am trying to open a link from my database into a black tab.

Can I try this: “target=\”_blank\“>”

Will this use the " without messing up the PHP script?

I think you may use it. Please let us know the html output of your php code.
Regards,
zico

Hi,

It wouldn’t work. I am publishing images from a database with links but I am struggling to get the links to open new windows.

Is there a standard method for doing this?

Please let us know the html output of your php code.

Hi,

What do you mean the HTML output?

Isn’t it the parts below. I’m new to mixing PHP and HTML.

echo “<a href=\”" .$link . “\”><img src=\“” .$image .“\” /> </a><BR />";

I think he is looking to see a sample result of your page. Show what the echo puts on your page at the end.

Hi,

it displays an image fitted with a link.

By html output I mean the source of the html page displayed in your browser as a result of running php code on server.
For Firefox: View–>Page source (or Ctrl-U)
For IE: View–>Source

Reply with the relevant html code to see where your problem is.

If you consider usefull here is a piece of code from one of my older projects. It works for me. Please note that $file is the file name and $thumb_name the thumb name already generated. If you are not using automatically generated thumbs you may replace with what you want.


<a href="/images/<?php echo ($file); ?>"><img src="/images/<?php echo ($thumb_name); ?>"  border='0' target='_blank'">Click here to view full size picture.</a>

Regards,
zico

Assuming by ‘external link’ you mean new tab/window like your 2nd post describes, the following would be simple enough…

echo("<a href='$link' target='_blank'><img src='$image' /></a>");

Because you’re using " it will parse the variables ($link, $image) without going in and out of the string (“…”).

Also by using ’ instead of " inside the echo, we don’t need to escape it each time.