I'm not much of a programmer, PHP is where I'm comfortable. And sometimes I find that I need to do things, such as arrange files or rename files on a mass scale on my computer. And I think I could do this with PHP but I can't of course.
So I was curious, is there a way I could run PHP files as kind of exe files.
EDIT: Fairly important point, using Windows.
just use php.exe (put it in your path) and the name of the php file you want to execute
You should have a look at php gtk
It's not as bad as you put it. PHP may be a very good tool for string related stuff like parsing, renaming etc. Especially if you know PHP.
To use php as script you should add #!/path/to/php as first line and set execution permissions on unixoid systems. In windows you can simply assign the php file ending with your php cli exe so you can click on them or use the script with the "start" command in the windows shell. But make sure that you write your scripts in a way that it is sensible to the current working directory. It may be different to what you might expect sometimes.
to be able to execute php files with double click, just like normal programs, go to the command line, then type
ftype php_script "C:\path\to\php.exe" "%1"
assoc .php=php_script
Check out WinBinder
Sure, just add #!/path/to/php to the top of the file, add the code in tags, and run it as a shell script.
Works fine - the php binary you use is either the cgi one or the purpose built CLI version.
http://www.php-cli.com/
http://php.net/manual/en/features.commandline.php
it would appear so, yes.
Download Wamp Server, install it. Once thats done, add the path to the php.exe to your PATH settings. You can do this by going to control panel->system->change settings->advanced->environment variables. Edit the PATH, add a ';' to the end of the line and then past the path to the php.exe. This is on Vista, it might be different on XP or Windows 7.
My path looks like this after: C:\Sun\SDK\jdk\bin;C:\wamp\bin\php\php5.3.0
Once thats done, you'll be able to execute a php file from the command line. You could create shortcuts too.
C:\Users\Garth Michel>php test.php
This is a test
C:\Users\Garth Michel>
I used php for years as a scripting language before I even bothered to use it as a web programming language.
maybe php is not the right tool to doing this and it's about time to learn another language...use this chance to expand your programming horizion
See the .reg file in this gist, it makes it possible to use .php files exactly like .bat files, e.g. my_script.php foo bar baz
Don't forget to edit paths to suit your setup.
http://www.appcelerator.com/products/download/ Still use html & css as a desktop app and now has support for php.
PHP based web apps like Wordpress and Mediawiki I think uses php to setup and configure itself. Just give IIS proper read/write rights and you can make a simple web app that does massive renaming, etc.. PHP doesn't have to always be used for writing out html.
See ExeOutput for PHP. It has excellent customization and MAGNIFICENT features. Yet it is not an IDE or something. It compiles your PHP+HTML into fully-fledged EXEs.
Related
So for an assignment, we have to create a 15 page website. But I was going to use some PHP for a few things. One of the requirements is that I write the files to a CD, set up to Autorun.
One of the problems I've discovered with PHP is that it has to run from a server. Does this mean that I can't use PHP for this assignment?
Edit: Size limit is 100MB
While it wouldn't be PHP on the CD itself, you can still use PHP to compile the components (header, footer, etc) and content of each of the pages into their final HTML files (and directories). In essence you'd be making a light static site generator.
Try FoxServ Win32 & Linux Edition
or
DWebPro
It's exactly what you need!
Php with embeded server should be the way to go.. So, You'll need some sort of portable variant of php 5.4+ on a cd and a shell script that calls it ... Anyway, there are still people using CD's nowadays? Weird. :D
I have a php project I'm working on using PhpStorm. I have a python script which manipulates my css file in a certain way before uploading it to the server (it's irrelevant to the question, but if you're curious, mostly related to language support).
I'd love to be able to run it directly from phpstorm, but I'm unsure how to do it (I'm guessing it's possible but I couldn't find any reference to something of the sort, and I'm kinda new to this IDE). I know I can rewrite the script with php but I'd rather not (I'm still a pythonist at heart).
Anyone had to tackle something of the sort?
Thanks in advance!
p.s. I'm running Ubuntu if that matters.
Use File Watcher plugin for that (should be bundled since v7 by default) -- this way such script will be run on each of desired modified files on save automatically.
http://confluence.jetbrains.com/display/PhpStorm/File+Watchers+in+PhpStorm
Alternatively you can use External Tools functionality and invoke it manually when desired.
http://www.jetbrains.com/phpstorm/webhelp/external-tools.html
According to the help page you can run scripts in the "Before launch". IMHO you can configure an external tool to be your python script (change +x to make it executable...).
Alternatively, I think you could install the python plugin (I've never tried it).
Don't think that I'm mad, I understand how php works!
That being said. I develop personal website and I usually take advantage of php to avoid repetion during the development phase nothing truly dynamic, only includes for the menus, a couple of foreach and the likes.
When the development phase ends I need to give the website in html files to the client. Is there a tool (crawler?) that can do this for me instead of visiting each page and saving the interpreted html?
You can use wget to download recursively all the pages linked.
You can read more about this here: http://en.wikipedia.org/wiki/Wget#Recursive_download
If you need something more powerful that recursive wget, httrack works pretty well. http://www.httrack.com/
Pavuk offers much finer control than wget. And will rewrite the URLs in the grabbed pages if required.
If you want to use a crawler, I would go for the mighty wget.
Otherwise you could also use some build tool like make.
You need to create a file nameed Makefile in the same folder of your php files.
It should contain this:
all: 1st_page.html 2nd_page.html 3rd_page.html
1st_page.html: 1st_page.php
php command
2nd_page.html: 2nd_page.php
php command
3rd_page.html: 3rd_page.php
php command
Note that the php command is not preceded by spaces but by a tabulation.
(See this page for the php command line syntax.)
After that, whenever you want to update your html files just type
make
in your terminal to automatically generate them.
It could seem a lot of work for just a simple job, but make is a very handy tool that you will find useful to automate other tasks as well.
Maybe, command line will help?
If you're on windows, you can use Free Download Manager to crawl a web-site.
I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library?
http://www.adp-gmbh.ch/win/misc/webserver.html
I just downloaded that and I am going to use that to work off of. Basically I am writing a serverside game plugin that will allow game server owners to access a web control panel for their server. Some features would be possible with PHP so this is my goal. Any help would be appreciated, thanks!
The PHP won't serve itself. What happens in a web server like Apache is before the PHP is served to the user it is passed through a PHP parser. That PHP parser reads, understands and executes anything between (or even ) tags depending on configuration. The resultant output, usually still HTML, is served by the web server.
There are a number of ways to achieve this. Modules to process PHP have been written by Apache but you do not have to use these. PHP.exe on windows, installed from windows.php.net, will do this for you. Given a PHP file as an argument it will parse the PHP and spit the result back out on the standard output.
So, one option for you is to start PHP.exe from within your web server with a re-directed standard output to your program, and serve the result.
How to create a child process with re-directed IO: http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx however, you won't be writing the child process, that'll be PHP.exe
Caveat: I am not sure from a security / in production use perspective if this is the most secure approach, but it would work.
PHP needs to be processed by the PHP runtime. I'm assuming the case you're talking about is that you have a C++ server answering HTTP queries, and you want to write PHP code out with the HTML when you respond to clients.
I'm not aware of any general-purpose PHP library. The most straightforward solution is probably to use PHP as a CGI program.
Here's a link that might be useful for that: http://osdir.com/ml/php-general/2009-06/msg00473.html
This method is nice because you don't need to write the HTML+PHP out to a file first; you can stream it to PHP.
You need execute the PHP page to serve the page it generates.
The easiest thing for you to do would be to add CGI support to your webserver in some basic form. This is non-trivial, but not too difficult. Basically you need to pass PHP an environment and input, and retrieve the output.
Once you have CGI support you can just use any executable, including PHP, to generate webpages.
I have a PHP script which includes one or two other libraries it depends on using the 'include' statement. To make it more easily portable, I would like to somehow 'compile' the script and the included libraries it into a single PHP script (in the same way that ack includes all its Perl dependencies in one file). Is there an easy way to do this in PHP?
Clarification: Compiling to a windows executable could be (part of) an acceptable solution, but the script still needs to run on *nix, where it is better to have PHP source code with '#!/usr/bin/env php' at the top.
I want to be able to drop a single file into the $PATH somewhere on any OS and have it work without needing extra PHP libraries to be installed as well.
Newer versions of PHP support a concept similar to jar files in java. Take a look at phar. You could package all of your application files into a single archive and run that.
The PHP packages ScriptJoiner or even better JuggleCode might help:
http://packagist.org/packages/codeless/scriptjoiner
http://packagist.org/packages/codeless/jugglecode
Both are built upon PHP-Parser (http://packagist.org/packages/nikic/php-parser), which makes it very easy to join scriptfiles.
There's no built in way to do that. I would recommend packaging your code up into a directory and distributing it that way. I do this with PHP, I place the code into a directory "something.module", and then have iterate through a modules directory, including the main file underneath each .module directory. But for something more simple, you could just have a structure like:
my_package/
my_package.php
include1.php
include2.php
my_package.php would include(realpath(dirname(__FILE__).'/inclue1.php')). All other scrits would just have to include('my_packahe/my_package.php')
Manually, you just remove all references of include/require, and "concatenate" the files together.
you should also strip the open and end tags ('<?php', "?>") before concatenation, and add them in the final file.
For one or two small libraries, it should - hopefully - "just work"...
phc allows this. Just run it with the --include flag, and it will combine all your code (well, every argument to an include, require, etc) into a single PHP file.
If you like, it can also compile it, but that's not required to combine them all into a single file.
You could write a custom script that opens all the files, removes the opening and closing tags, and concatenates them together and saves as one file. should be pretty easy to do.
Or you can use a php compiler. It will do a bit more than what you are looking for, but if you just want one file, you run your dev project through one of these.
http://www.phpcompiler.org/
http://www.roadsend.com/home/index.php?pageID=compiler
You might also be able to use the built in php bytecode compiler to compile everything to byte-code and stick it in one file.
http://us.php.net/bcompiler