Minify CSS and JavaScript files with PHP [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP auto minify. Is there any?
I'm using PHP minify (http://code.google.com/p/minify/)
I have to go to my webpage, create the url's, click upload, copy the the link of the new compressed file into my PHP file as explained here: http://www.mrclay.org/2008/09/19/minify-21-on-mrclayorg/
This works fine, but how can this be automated? Is there a PHP class for this or can I use one of the PHP classes already included in minify?

I think you have two main options really.
Use cURL to call the google code minifier. http://php.net/manual/en/book.curl.php
Use a different minifier that you can run locally. Try:
http://developer.yahoo.com/yui/compressor/ (Requires Java runtime)
http://www.crockford.com/javascript/jsmin.html (Windows only)

You can write a wrapper with CURL to send your files to the server, gets the returned text and outputs it to the client.
Beware, though, that it will slow down your server a lot (it will minify the code every time someone asks for it). So you would need a caching mechanism to do it only once.

Related

run PHP code inside HTML without using xampp and apache? [duplicate]

This question already has answers here:
How can I run a php without a web server?
(4 answers)
Closed 2 years ago.
i know there are many similar questions but tbh none of them really fit.
I have no problems running the php part of my Webpage and everything works fine. Now im asking if there is a way to run my webpage including the php part without using having to start apache and typing in localhost.
I just wanna open up my html document with a browser and display it, nothing else. However then, the php code isnt really executed but its necessary for me as it displays an essential table with data. And no I cant use javascript for a very specific reason. I have to use php for my project but its a bit inconvenient having to start apache everytime and i just want to open up the document with firefox for example.
Unfortunately, this will not be possible as PHP is a server side language. As such, you will have to have an application to serve the content. With HTML, you are able to open it directly and display as the client (Browser) is able to read it directly. Browsers do not read PHP - when the server compiles the PHP, it is only sending the DOM (HTML, etc.) to the browser.
Like other people said, PHP is a server side language so you need to run a server on your machine.
But maybe you could try using small local server like the Symfony Local Server
It should be faster to start than apache.

how to take a screenshot of a loaded webpage using php? [duplicate]

This question already has answers here:
Website screenshots
(18 answers)
Closed 6 years ago.
I need to take screenshots of few web pages and save them in a folder using php.
I want to do this using a php script, is there a way I can render those webpages and take screenshot of a particular area after the website is fully loadedd? - I'm using windows.
I tried using wkhtmltoimage but it takes low quality screenshots and also it takes the screenshot before the whole page is loaded, so some images of the webpage are not appearing in the screenshot, is there a way to do this using php?
Please help php specialists. Thank you
PHP runs on server side, so to be able to take screenshots you need something to render HTML (a browser-like script) and generate a image of it. This script will do that (wkhtmltoimage too):
HTML2PS:
http://freecode.com/projects/html2ps_php
But I still think the best solution will be using javascript. Of course, only the client will have access to the screenshots, and maybe you can upload the image to the server. A client browser is better than any kind of server script.
If that is the case, I would suggest using HTML2CANVAS:
HTML2CANVAS: http://html2canvas.hertzen.com/
The best server solution will be a linux distribution with a google chrome installation and a local script to take screenshots. That is the only way to get accurate screenshots of a web page that may contain javacript/HTML5/animations and other difficult to render stuff.
JavaScript / HTML5 / Canvas
It could be hard to code it only in PHP. In your case I think I would follow those instructions:
Using HTML5/Canvas/JavaScript to take screenshots
PHP
Or if you really want use only PHP, it should help you:
Website screenshots using PHP

Trouble running my PHP files [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Question about php and dreamweaver?
I am having alot of trouble running my php file. I downloaded XAMPP and have both Apache and MySQL running. Do I need to save the file in a certain place, and what does Dreamweaver mean when it says:
To preview pages containing server-side code, you need a testing server. Would you like to specify one now?
I have good enough knowledge in HTML and CSS, and have gotten websites running, but I can't seem to get PHP to work. When I just run the code from google chrome plainly it looks like this:
"Hello World"
"; phpinfo(); ?>
You can put your PHP-files into the xampp/htdocs folder, e.g. xampp/htdocs/hello.php and then open it in your browser at http://localhost/hello.php.
The URL must say localhost or whatever you set it to in order to render a PHP page. You also need to make sure PHP handlers are working and correctly parsing PHP files.

How run an enrypted php file in a local server? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Code obfuscator for php?
Can I encrypt PHP source or compile it so others can’t see it? and how?
How is it possible to protect PHP code?
I want to encrypt PHP code so that others should not modify and cannot view the code. If I run that encrypted PHP file in the browser its functionality should work.
I have used few codes and some software like PHP Bambalam PHP EXE Compiler/Embedder ,phc-win,zzee php etc., with those I am able to encrypt PHP code but failed to run in the server. It was showing Php encrypted code instead of its functionality.
Can any one suggest me a way to encrypt a file which should be free and run that encrypted code in the server?
For ionCube (which I use), you also need the loaders installed on your server:
http://www.ioncube.com/loaders.php
Something must decrypt the file.
You don't need to do this. PHP code is run on the server, the browser never downloads it.

Open documents(pdf,doc,docx,txt) in browser page using php (without using google docs viewer) [duplicate]

This question already has answers here:
Is there a PDF parser for PHP? [closed]
(7 answers)
Closed 8 years ago.
My question is that i want to open documents(pdf,doc,docx,txt) in browser page using php (without using google docs viewer) can any one help me?
Some of these are doable. Some, not so much. Let's tackle the low-hanging fruit first.
Text files
You can just wrap the content in <pre> tags after running it through htmlspecialchars.
PDF
There is no native way for PHP to turn a PDF document into HTML and images. Your best bet is probably ImageMagick, a common image manipulation program. You can basically call convert file.pdf file.png and it will convert the PDF file into a PNG image that you can then serve to the user. ImageMagick is installed on many Linux servers. If it's not available on your host's machine, please ask them to install it, most quality hosts shouldn't have a problem with this.
DOC & DOCX
We're getting a bit more tricky. Again, there's no way to do this in pure PHP. The Docvert extension looks like a possible choice, though it requires OpenOffice be installed as well. I was actually going to recommend plain vanilla OpenOffice/LibreOffice as well, because it can do the job directly from the command line. It's very unlikely that a shared host will want to install this. You'll probably need your own dedicated or virtual private server.
In the end, while these options can be made to work, the output quality is not guaranteeable. Overall, this is kind of a bad idea that you should not seriously consider implementing.
I am sure libraries and such exist that can do this. Google could probably help you there more than I can.
For txt files I would suggest breaking lines after a certain number of characters and putting them inside pre tags.
I know people will not be happy about this response, but if you are on a Linux environment and have pdf2html installed you could use shell_exec and call pdf2html.
Note: If you use shell_exec be wary of what you pass to it since it will be executed on the server outside of PHP.
I thought I'd just add that pdfs generally view well in a simple embed tag.
Or use an object so you can have fall backs if it cannot be displayed on the client.

Categories