The COM function built in PHP4 is quite attractive for developing programs in win32 environment, but there are still not many related technical documents. This article uses three examples to differentiate MSoffice2000Word, Excel, and AdobeDistiller.
COM functions built in PHP4 are quite attractive for developing programs in win32 environment, but there are still not many related technical documents. This article will illustrate how to apply COM functions in PHP with three examples of processing MS office 2000 Word, Excel, Adobe Distiller.
The COM technique was developed and developed by Microsoft over the past few years. the related terms mentioned in this article include OLE, OLE Automation, ActiveX, and COM. these terms have the same meanings, it uses a piece of encapsulated code (object) to complete some functions of a windows Exploitation Program. The PHP4 COM function can connect to an object instance and apply its methods and attributes.
If you want to apply the following example source code, please refer to my configuration.
Windows 98-MS Office 2000
Apache 1.3.9 Windows
PHP4.02 Dev (08-20-00) Running as CGI
COM mark in PHP4
Now let's get started. to instantiate a component with the COM of PHP4, we need the new controller and the 'ole program identifi' of the object ':
$ Instance = new COM ('$ identifier ');
?>
Because COM is a reserved word of PHP4, it transmits the identifier of this object to a structure function. now we get an example of this component. according to the nature of the OOP class, we can easily visit its methods and attributes.
For example:
$ Instance-> [Object]-> [method1]-> [method2]->...-> [property];
?>
That's simple!
The structure of OOP cannot work in PHP (because of the title of PHP syntax, attribute name. the value is invalid characters, such as vertices and parentheses), so PHP4 provides two corresponding functions:
Bool com_set (class com_object, string property name, string property_value );
Mixed com_get (class com_object, string property_name );
?>
Finally, PHP4 also supports the DCOM technique and can create an object instance on a remote computer.
$ Instance = new COM (string 'component name', string 'remote _ server_address ');
?>
Note:This is to use the DCOM command to set PHP. In the future, PHP developers will provide support for DCOM in Unix.
Identifiers, methods, and attributes
The identifier is a string as follows:
MS Word: 'Word. application' or 'word. Application.9'
MS Excel: 'Excel. application' or 'Excel. Sheet'
ADOBE Acrobat: 'exch. application' or 'invalid Distiller. invalid distiller'
For the last identifier, it is not easy to obtain an accurate object identifier. If you cannot visit the VBA document, you can search for the windows Registry and find it in HKEY_CLASSES_ROOT. then you can get the names of some exploitation programs. Put the valid object ID on your machine in the CLSID subfolder.
The exploitation program usually provides documents to clarify its COM methods and attributes. In office2000, you can run a program, open the VBA editor, and select the object editor. . Enter a method name or attribute name in the library, right-click a class or member name in the following window, and click help, you will get a description of this class or member. You can also refer to MSDN. An example of an Excel: http://msdn.microsoft.com/library/officedev/off2000/xltocobjectmodelapplication.htm