concatenating strings in php, why doesn't this work?

GeX

GeX

Soldato
Joined
17 Dec 2002
Posts
6,981
Location
Manchester
Code:
<?
    $dir = "img/whittingham";

    if (is_dir($dir)) {
        $fd = @opendir($dir);

        if($fd) {
            while (($part = @readdir($fd)) == true) {
                if ($part != "." && $part != "..") {
                    $file_array[] = $part;
                }
            }
        }
    }


for ($x=0; $x < sizeof($file_array); $x++) {
      echo "<img src=\"". $dir."/".$file_array[$x] ."\"><br />";

}
?>

right.. that does what it is supposed to, scans the dir and outputs all the images. now suppose i want to add an alt elemenent to the img tag, surely it would be

Code:
."alt="moo""

meaning the output line is;

Code:
echo "<img src=\"". $dir."/".$file_array[$x] .alt"moo""."\"><br />";

but if i do that, i get a parser error. i'm a newbie at php, and i can't see where i'm going wrong here.
 
thanks for the help guys, so many different ways of doing the same thing eh. i'll modify the script to use foreach instead, and pick my new favourite way of making strings :D
 
Back
Top Bottom