Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100 off


PHP Tutorials and Scripts   




Title: Using COM with php    Marked Cool    (Review this resource)
Author: econner
Posted On: 2004-11-17
Category: Home > PHP Tutorials

Popularity: 1 points out of 10    

Description: Using COM to open ie and word docs.

Total Hits: 1686     Total Votes: 0     Total Points: 0 (0 reviews)        [ Download ]   

Page Navigation:  [1]


Using COM with php


In this tutorial I will show you how to create a php app that you can run COM objects with (ie, word etc.). It will run off of your comp and be distributable to other users.
Ok so what is com?

" COM is an acronym for Component Object Model; it is an object orientated layer (and associated services) on top of DCE RPC (an open standard) and defines a common calling convention that enables code written in any language to call and interoperate with code written in any other language (provided those languages are COM aware). Not only can the code be written in any language, but it need not even be part of the same executable; the code can be loaded from a DLL, be found in another process running on the same machine, or, with DCOM (Distributed COM), be found in another process on a remote machine, all without your code even needing to know where a component resides." --www.php.net


Ok now download this file.
It contains 4 files:

php4ts.dll - contains all the php functionality
start comIE.bat - this will start the application
php.exe - this will run the php
comIE.php - this will contain the php code for the app

For fun lets create an app that will navigate to your email server and log you in. (mail.com will be my example)
To initiate a new COM object you pretty much only need one line:
$b = new COM("InternetExplorer.Application");

Ok now initiate the properties for this new ie window.
$b->toolbar = 0;
$b->statusbar = 1;
$b->visible = 1;


//navigate to the server
$b->navigate("http://www.mail.com/");

//set some more attributes
$b->document->body->all['login']->setAttribute('value', 'username');

$b->document->body->all['password']->setAttribute('value', 'password');

//submit the form
$b->document->body->all['Go']->form->submit();


A few useful ie functions

$b->Document->body->innerHTML; //will return the html of the page
$b->ReadyState // will return current ie readystate

Microsoft word

Now for some word stuff:
$word = new COM("word.application");
//show the word app
$word->visible = 1;
//open a new document
$word->Documents->Add();
//add some text to the document
$word->Selection->TypeText("this is some sample text");
//save the document as sampleword.doc
$word->Documents[1]->SaveAs("sampleword.doc");
//close word
$word->Quit();
//free object resources
$word->Release();
$word = null;


The reaches of COM are pretty much endless. This is just a sample of what you can do with it. Google it, you'll find tons :).



Page Navigation:  [1]



© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.