Page 1 of 1

HTML and PHP

Posted: Sat Jul 20, 2002 6:10 pm
by Fegero
I am a newbie with PHP but I am ticked off at myself for not knowing something probably simple.

I am working on a web site.

My index.html is in FOLDER A
A picture I want to see is in Folder B

The index is simple it says to call results.php file.
The php file does a search in the database and grabs a name.

Now my problem. I want to take that name and then open the picture. In other words open the picture called "name.gif". Since I have too many "marks, what do I need to do: I have the typical html code.

<img border="0" src="MyFolder\picture.gif">

I tried with an echo but too many quotes!

thanks,

Fegero

feger585@yahoo.com

Posted: Sat Jul 20, 2002 6:43 pm
by Bill H

Code: Select all

echo "<img border="0" src="MyFolder/picture.gif">";
Note the forward slash in the file pathname.
The backslash is the "escape" character and tells the php to print the following character rather than parse it.

Posted: Sat Jul 20, 2002 6:46 pm
by gnu2php
Darn, Bill H, I wasn't quick enough. :wink:

Anyway, here's what I was posting--

I have come up with three possible solutions:
  • 1. You can begin the path with a / (slash), and enter the full path, like this "/path/MyFolder/picture.gif"

    2. You can use "dots" like this "../MyFolder/picture.gif" (.. is the previous folder).

    3. You might need to use a forward slash /, instead of a backslash \ in the path. A backslash \ is for "escape" characters, so "MyFolder\name.gif" inserts a newline character (\n).

Posted: Sun Jul 21, 2002 5:52 am
by twigletmac
If you don't want to have to escape all the double quotes in your HTML put the string in single quotes:

Code: Select all

echo '<img border="0" src="MyFolder/picture.gif">';
Note that PHP doesn't parse things in single quotes so if you had a variable in the above string you'd have to do something like this:

Code: Select all

echo '<img border="0" src="MyFolder/'.$picture_name.'.gif">';
Mac

Posted: Sun Jul 21, 2002 9:27 am
by fatalcure
or the other way around:

Code: Select all

echo "<img border='0' src='MyFolder/picture.gif'>";
:)

Posted: Sun Jul 21, 2002 5:41 pm
by hob_goblin
its frowned upon to use single quotes in html

Posted: Sun Jul 21, 2002 6:09 pm
by galena
Or you could even do it like this:

Code: Select all

?>
<img border="0" src="MyFolder\<?=$name?>.gif"> 
<?
Especially for larger pieces of html, I often prefer this.

Michiel