tags:

views:

80

answers:

1

Hi Guys,

I have a php script (generator.php) which generates certain HTML/XML/SVG depending on various conditions. I want to embed the output of this script in my homepage (home.php)

eg. Let generator.php always generate an SVG document (complete with SVG NS and DTD). Now I want to embed this generated image in the output of home.php

I have tried <object>, <embed> and <iframe>. None seem to work. Does anybody know how to accomplish this?

+1  A: 

You may use either:

  1. include file on the PHP side. So on the home.php page simply include the generator.php file at the point where you want the output.

OR

  1. Use AJAX on the client side. On home.php when the page loads in the browser you can make a simple AJAX call to generator.php and dispay the output at the desired place on the page.

Update (Considering the comment below): Did you try this:

<object type="image/svg+xml" data="generator.php" width="300" height="200"></object>

for the SVG?

Vincent Ramdhanie
This would work only if the output of the included php file (generator.php) is HTML. If the output is SVG, it will not be rendered!
Crimson
As long as you send the proper mimetype for the SVG output [Content-type: "image/svg+xml"] then it should work fine with <object>, <iframe> or <embed>. You may have to make sure that the browsers don't cache the result, e.g using a no-cache header or by changing the url so that it includes a random/unique part (generator.php?foo=asdb323423) or something like that.
Erik Dahlström
It worked by sending the MIME type as an HTTP header from PHP using the header() call. Thanks for pointing out that it was a MIME type problem :)
Crimson