You are here: Re: Can't Escape « PHP Programming Language « IT news, forums, messages
Re: Can't Escape

Posted by Ron Barnett on 09/11/07 21:57

"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091114413816807-PostInGroups@wherevercom...
> Hi all,
>
> I'm trying to do something simple and grabbed a snippet from the php
> manual for reading files in a directory. The snippet echos out a nice list
> of files.
> <?php
> //Open images directory
> $dir = opendir("images");
> //List files in images directory
> while (($file = readdir($dir)) !== false)
> {
> echo "filename: " . $file . "<br />";
> }
> closedir($dir);
> ?>
>
> So with my very limited PHP skillset I am trying to concatente the $file
> variable in an image tag. I can't seem to escape this the right way. I've
> done some cutting and pasting and commenting trying to figure this out.
> (keep the laughing down. :)
>
> <?php
> //NOT WORKING - shows the little blue question mark box
> echo "<img src = \"/DSC01351.jpg\">";
> //Works
> echo "<br>";
> //Open images directory
> $dir = opendir("images");
> //List files in images directory
> while (($file = readdir($dir)) !== false)
> {
> // Below Works---Shows the filename like DSC01351.jpg
> echo "filename: " . $file;
> //NOT - shows the little blue question mark box
> echo "<img src=" . $file . ">";
> //NOT - shows the little blue question mark box
> echo "<img src=\".$file.\">";
>
> }
> closedir($dir);
> ?>
>
> Just amazingly frustrated with something that is so simple. I'v tried a
> lot of ways to escape the quotes in the img tag but can't mahe it work.
> left a couple of example...
>
> Any help would be greatly appreciated.
>
> TIA!
Hi Confused,
well you've certainly circled all around it !

First, a basic error,
You've listed the files in a particular directory but neglected to tell the
HTML image tag what the directory name is !

Second, not really an error, but you can nest single quotes inside double
quotes to avoid all the confusing escaping.
Try This
<?php
//Open images directory
$dir = opendir("images");
//List files in images directory
while (($file = readdir($dir)) !== false) {
echo "<img SRC='images/".$file."'><br />";
echo "filename: " . $file . "<br />";
}
closedir($dir);
?>
note the SRC attribute is in single quotes with the double quotes
encapsulating the srings.

Cheers

Ron

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация