HTML and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fegero
Forum Newbie
Posts: 7
Joined: Sat Jul 20, 2002 6:10 pm

HTML and PHP

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post 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).
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

or the other way around:

Code: Select all

echo "<img border='0' src='MyFolder/picture.gif'>";
:)
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

its frowned upon to use single quotes in html
galena
Forum Newbie
Posts: 7
Joined: Tue Jul 16, 2002 4:46 am
Location: Netherlands

Post 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
Post Reply