-2

I'm looking at a PHP logic problem for me, but I can't fix it, so I ask you guys here. How can I call/combine the underneath PHP img with the var string method?

I would like to call an image with PHP:

<img src="<?php echo $this->getSkinUrl('images/prev.gif'); ?>

But I would like to call the php from the following string:

var str_buffer = new String (
 "<table width=\"100%\">\n"+
    "<tr>\n <td>\n"+
    "<img src=\"prev.gif\" width=\"16\" height=\"16\" border=\"0\""+
    " alt=\"previous month\"></td>\n"+
    "</tr>\n</table>\n"
);
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
Ruud
  • 249
  • 2
  • 8
  • 22

1 Answers1

1

If I understand correctly you want to implement the method used in the PHP for calling a function, within the Javascript code?

If so, You need to enclose the Javascript segments within a PHP output statement. Eg.

    echo 'var str_buffer = new String (
 "<table width=\"100%\">\n"+
    "<tr>\n <td>\n"+
    "<img src=\"' . $call->getSkinUrl('images/prev.gif'); . '\" width=\"16\" height=\"16\" border=\"0\""+
    " alt=\"previous month\"></td>\n"+
    "</tr>\n</table>\n"
);';

Aditionally, you will need to implement the class/object on the page where you want to use it.

nand
  • 627
  • 5
  • 11
  • Sorry for all the fuss about the question. This is actually the answer I was looking for. Thank you very much! – Ruud Dec 27 '11 at 14:18
  • 2
    Just an FYI, you shouldn't use `new String` in JavaScript. When you use `new String` you have an object, not a string. So, `"ABC" === "ABC"`, but `"ABC" !== new String("ABC")`. – gen_Eric Dec 27 '11 at 14:21