0

Ok, I want to print an 'img' from php to html. The php file is included inside a html div. It works when I printf the image without the height and width attributes, but when I include them it stops working.

Following code works. No height or width.

$value='../images/cal.png';
printf (
    '<img src=%s >',
    $value
    );
unset($value);

Following code does not work. height and width included.

$value='../images/cal.png';
printf (
    '<img src=%s height=100% width=100%>',  
    $value
);

unset($value);

I'v tried quoting the width and height, but still nothing. What am I missing?

It works with height and width when I use echo, but I am going to be making the code more complicated, so I want to do it in printf. Its been simplified for the question.

Thanks guys!

seamus
  • 2,681
  • 7
  • 26
  • 49
  • Sprintf but same answer: http://stackoverflow.com/questions/3666734/php-sprintf-escaping – AlexP Jul 28 '13 at 22:31
  • 1
    You have invalid HTML there needs to be quotes around the 100% values. Do what @Amine suggests –  Jul 28 '13 at 22:32

1 Answers1

0

Maybe because width and height doesn't like 100% ? Try with :

$value='../images/cal.png';
printf (
    '<img src=%s height="100" width="100">',  
    $value
);

unset($value);

Why are you making the code more complicated ? Is the following not working ?

echo '<img src="'.$value.'" width="100" height="100" />';
Mohamed Amine
  • 2,264
  • 1
  • 23
  • 36