Dynamically populate SVG file using PHP? - php

I have the following SVG example graph:
http://jovansfreelance.com/bikestats/circos/travels.svg
You can see the source code from there, it's all client-side.
The graph works using sample data. Now, what I need to do is populate is dynamically from the database (or from a file on the server which I could generate using PHP).
Placing PHP code directly into the SVG file doesn't work. Using an onLoad AJAX call doesn't work. It won't let me include jQuery at all. So how do I go about this? I know there's a way but I'm completely new to SVG files.

There's no real difference between generating SVG from PHP and generating HTML from PHP. You just need to override the default content-type header (header('Content-Type: application/svg+xml');).
Of course, you still need a .php file extension as your server won't (by default) be set up to parse .svg files for PHP code.

Related

HTML Page convert to php to use it as homepage for Wordpress

I want to use a static page for the homepage for faster load times. (In Wordpress)
But after the converting HTML to PHP with an online converter, it failed, I get only a 500 Issue Code and in the source code is nothing.
There's no point of converting your static HTML page to PHP, unless you want to add some content that's frequently updated (for example posts in your blog).
If you want to create a dynamic website, then you should consider writing it in PHP (you can rename your file's extension, no further conversion is required since every line of PHP code is positioned in between <?php and ?> tags). For example: if your page is called index.html, you can simply change its extension to index.php and it will work fine.
BUT! You'll need a server (or a virtual server) to run your PHP scripts (simply opening the PHP file will result in showing HTML and pieces of PHP code instead of executing it).
Why you want to convert HTML to PHP?
The PHP is generally used to generate HTML pages..
And even at the page load level, a PHP page will have to generate the HTML to be output, while an HTML code already written will only need to be read by the server and served to the client.
So I think you read some article about someone who is not very experienced in the industry.. :-)

Is it Possible to to include only php material and skip html text while including a php file?

I have a file that prints a variable from mysql database via php say it is called independent.php. if we open the file via localhost/independent.php the file displays the information with html.
Is it possible to include independent.php in another php file, and only display the contents generated via php and not the html of independent.php so that using ajax the new html appear?
If you want to use only specific parts of your code, make it modular. Break it down into functions and/or classes. Separate the HTML output from the part that fetches data so you can call both independently. There's no other sane way.

Php display contents of pdf

Is it possible to print the contents of a pdf using php ,javascript or jquery
There is a jQuery PDF document viewer based on PDF.js available here:
http://dev.funkynerd.com/projects/jquery-pdfdoc/wiki
It renders the PDF on the client in javascript and so does not require any client-side software other than a relatively modern browser.
No for the JavaScript/jQuery piece, on the PHP side if you're using a library to read the files then that's an option, for your PDF options in PHP check out this question.
If you just want to display the content to the user though, just returning the PDF itself and letting their client-side viewer of choice do the work would be my first option.

Using PHP to generate screenshots from an HTML source

I've got an idea for a site that would generate png or jpeg screenshots of webpages on the fly. The end user would never see the pages, but the HTML would be turned into a screenshot instead and the end user would see that screenshot.
How can I get started on this? I guess what I'm looking for is some kind of PHP function that takes the HTML as an argument and then produces an image file in a specified location.
As far as I know, PHP does not do this.
You can, however, find a solution using external tools.
Here is how I would do it
Generate the HTML
I would pass this HTML to a external tool using exec. There is, for instance this one.
Then, display the generated picture
http://www.zubrag.com/articles/create-website-snapshot-thumbnail.php

Generate XML with PHP and pass it to an SWF

In the past I have created a php file that generates the XML and then referenced it in place of the xml file and it has worked. I am trying this with a precompiled flash app and it is not working.
Any ideas why?
It works if I run the script, save it and then reference that file to the swf. I would rather not generate a file to the filesystem if possible. Anyone any solutions?
IF you pull the php page up in the browser are you sure that:
The file has no white space preceding the XML prolog (<?xml version="1.0" ... ?>)
The XML is wellformed
Another thing to check would be to look in firebug on the net panel... it shoudl show all the requests/responses made - including those done by flash (im assuming this is embedded in a web page). Look and make sure your flash is actually looking for the file you think its supposed to be looking for.
Without further information (code etc) I can only guess:
Are you trying to execute it on a server? php needs to be interpreted to generate the actual XML output, so if you don't put it on a webserver (that supports php), no content will be generated and the flash movie just sees the php code.
Check the content of the loaded php/XML file, trace it into some text field for debugging, so you can check if the actual content is being loaded correctly.
Listen for all available events of the URLLoader object. Maybe there is some IO error, you are not seeing. Alternatively you can also use the Flash debug player to see if errors are being thrown.
Also: What ActionScript version are you using?
Without seeing any of the code I would suspect the content type header isn't being set correctly and the php script is sending as html.
You can set the content type with the header funciton:
header('Content-Type: text/xml');
I'd suggest checking if some setting in your php.ini causes the output to be compressed (zlib.output_compression or ob_gzhandler).

Categories