Click to See Complete Forum and Search --> : Another echoing question


comptech520
03-03-2006, 09:48 PM
Hello Again,

Here is something else I am trying to echo
On this line: $img = "<img src=\echo $photo_dir";
I want to echo the path thats listed under $photo_dir, but its set up wrong.

Me and my syntax errors :eek:
= preg_replace("/[^0-9]/", "", $_GET['img']);
$img .= $_GET['img'].".JPG\" alt=\"\" />";
echo $img;
?>

comptech520
03-03-2006, 10:25 PM
Got it :) Took some info from my last post

NogDog
03-03-2006, 10:26 PM
You need to divest yourself of the idea of echoing variables within PHP expressions: echo is only for directly outputting its argument to the browser. Within a double-quoted string, variables will be "interpolated" (i.e.: their value will be used) without having to do anything special. (For array elements and special circumstances where the parser can't tell where the variable name ends, you need to wrap it in curly braces.) So...

<?php
$img = "<img src=\"$photo_dir";
$_GET['img'] = preg_replace("/[^0-9]/", "", $_GET['img']);
$img .= $_GET['img'].".JPG\" alt=\"\" />";
echo $img;
?>