PHP开发Windows桌面应用程序实例
PHP_GTK2.0 开发桌面应用程序
php gtk 官方网站
http://gtk.php.net/
官方有gtk的中文手册 具体安装请参见 手册
更简单的方法是用另外一款软件 名字叫做gnope
下载地址:http://www.gnope.org/download.php
安装过程很简单 安装好之后 在桌面会有个PHP-Gtk2 Applications 的快捷方式图标
双击该图标 会出现一个php的桌面程序 里面列出了所有的demo 有控件演示 还有游戏(前提是安装时选择了安装游戏)
应用详细讲解:
http://www.16ec.com/tp15/site/index.php和http://blog.csdn.net/zhangking/archive/2010/08/20/5825416.aspx
看过这些程序 你是不迫不及待要自己莱写一个桌面应用程序了啊
下面就给出一个简单的登陆程序:
?
<?php if (!class_exists(‘gtk’)) { die("lease load the php-gtk2 module in your php.ini\r\n"); } function login(GtkWindow $wnd, GtkEntry $txtUsername, GtkEntry $txtPassword) { $strUsername = $txtUsername->get_text(); $strPassword = $txtPassword->get_text(); $errors = null; if (strlen($strUsername) == 0) { $errors .= "Username is missing.\r\n"; } if (strlen($strPassword) == 0) { $errors .= "No password given.\r\n"; } if ($errors !== null) { $dialog = new GtkMessageDialog($wnd, Gtk::DIALOG_MODAL, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, $errors); $dialog->set_markup( "The following errors occured:\r\n" . "<span foreground=’red’>" . $errors . "</span>" ); $dialog->run(); $dialog->destroy(); } else { $wnd->destroy(); } } $wnd = new GtkWindow(); $wnd->set_title(‘Login’); $wnd->connect_simple(‘destroy’, array(‘gtk’, ‘main_quit’)); $txtUsername = new GtkEntry(); $txtPassword = new GtkEntry(); $lblUsername = new GtkLabel(‘_Username’,true); $lblPassword = new GtkLabel(‘_Password’,true); $btnLogin = new GtkButton(‘_Login’); $btnCancel = new GtkButton(‘_Cancel’); $lblUsername->set_mnemonic_widget($txtUsername); $lblPassword->set_mnemonic_widget($txtPassword); $btnCancel->connect_simple(‘clicked’,array($wnd,’destroy’)); $btnLogin->connect_simple(‘clicked’,'login’,$wnd,$txtUsername,$txtPassword); $tbl = new GtkTable(3,2); $tbl->attach($lblCredit,0,2,0,1); $tbl->attach($lblUsername,0,1,1,2); $tbl->attach($txtUsername,1,2,1,2); $tbl->attach($lblPassword,0,1,2,3); $tbl->attach($txtPassword,1,2,2,3); $bbox = new GtkHButtonBox(); $bbox->set_layout(Gtk::BUTTONBOX_EDGE); $bbox->add($btnLogin); $bbox->add($btnCancel); $vbox = new GtkVBox(); $vbox->pack_start($tbl); $vbox->pack_start($bbox); $wnd->add($vbox); //$lblHello = new GtkLabel("This is my first php talbe application\nhaha"); //$wnd->add($lblHello); $wnd->show_all(); Gtk::main(); ?>
?
在 Windows 上安装使用 Gnope
使用 Gnope 在 Windows 上安装和维护 PHP-GTK 2 已经被证明几乎是最简单的方法。 Gnope 是全功能的 PHP-GTK 2 安装包,包含 PHP 5.1 、GTK 2.6 和 PEAR 。 简单的点几下鼠标你就可以安装完成!
只要从 gnope.org 下载安装包,并跟随屏幕上的指引。 Gnope 也拥有它自己的 PEAR 自动安装频道, 那里你可以下载 PHP-GTK 2 程序添加到官方的 PEAR 包中。 例如从 Gtk2 category 。
手工安装
从 PHP-GTK 2 下载 页面下载 PHP-GTK 2 的针对 Windows 的 Alpha 版本二进制发行包。解压缩文件到指定目录。 一个名为 php-gtk 的目录将会创建,并包含发行版的所有内容。
你需要 php.exe (CLI 版本)和 php5ts.dll ,这两个都可从 PHP 5 的 Windows 发行版中获得, 并且放置到 php-gtk 目录。如果你希望使用这个 php.exe 的其他扩展,请确保你已经存放二进制文件于此。
之后,你必须设置环境变量 PATH 包含发行包中的 gtk+2.6.9 目录。 你也可以让批处理文件 gtkpath.bat 在运行时设置适当的 PATH 变量用于当前命令行会话中。
从 CVS 编译
这里仅仅包含在 Windows 上安装 PHP-GTK 2 最主要的步骤。如果你希望了解更多内容, 请从 CVS 上获取 win32/README.win32.txt 并阅读。
from: http://gtk.php.net/manual/zh_cn/html/tutorials/tutorials.installation.windows.html
=============
WinBinder
让phper
可以在window
系统开发桌面软件
WinBinder 是一种开源的 PHP 动态扩展(.dll) ,也算是脚本编程语言,为php 在window 下的开发提供用户界面UI ,它负责调用window 的API 接口。其运行 PHP 程序员轻松地使用 PHP 创建 Windows 应用程序。当然,这个只能在 Windows 下运行。本身是一个软件,php 程序员可以通过这个软件开发界面。官方网站说得很不错,无须编译php. 只要保存文件扩展为.phpw ,然后用 php.exe 打开就可以运行。具体开发感受如何,要试验一下才知道。初步感觉不会比php-gtk 差。
可以在此处下载到 WinBinder 的包 , 下那个 .zip 包,一般不需要用 .exe 的。下完之后解压缩,将 winbinder_xxx\PHP\PHP4\ext 目录下的(如果用的是 PHP5 则复制 PHP5 目录下的) php_winbinder.dll 复制到 PHP 扩展目录下,一般在 C:\php\extensions ,然后修改 php.ini 文件,加上:
extension=php_winbinder.dll
然后到打开命令行(cmd ),进入到 winbinder_xxx\Code\Samples 目录下,运行:
C:phpcliphp.exe manytests_main.phpw
这样就可以看到 Windows 窗口了,测试用的例子很多,可以都试试。我试了一下中文,还是支持得不错的,想想也是,WinBinder 是通过扩展的方式,加载到 PHP 中,其调用的都是 Windows 的 APIs 。实际上可以将 WinBinder 分为两层,一层是底层,叫 API 层,作为 PHP 扩展直接连接 Windows 的 API ,并为第二层(高层,叫 PHP 层)提供统一的调用接口。
Hello, world 代码示例
include("../inc/winbinder.php");???????????????????????????????
//
包含 WinBinder PHP
库文件
wb_create_window(NULL, PopupWindow, "Hello world!", 480, 320); //
创建 Windows
应用程序
wb_main_loop();????????????????????????????????????????????????
//
进入消息循环
?>
?
winbinder 的安装版的安装与配置
首先去http://winbinder.org/files/WinBinder-0.46.0.exe 下载winbinder ,这是一个安装版的,下载后双击安装。
1 、next
?
2
、next
?
3
、选择安装路径然后next
,这里我选择的是d;/winbinder
?
4
、选择php
的版本,我这里的是php5.1
?
5
、选择下载的服务器,选择台湾比较快(
又只有台湾的选项而没有中国的,气愤)
?
6 、next
?
?7
、install
?
8
、等待
?
?
9
、安装完成后点确认就行了。可以做第10步了。 ?
10 、安装好后打开D:\WinBinder\phpcode\examples ,任找一个.phpw 扩展名的文件,选择打开方式为D:\WinBinder\binaries\php51\php-win.exe 。
?
现在已经可以运行以.phpw 为扩展名的文件了。例如
这里要讲解几个问题
1:
我们可以选择的打开方式有三种,分别是php.exe php-win.exe php-cgi.exe
如果打开方式选择的是php-cgi.exe
那么在运行的时候,就会有一个命令提示符窗口出现,在实际应用中这个窗口也许看来很多余,但是在调试的时候可是很有用的哦
他能够提示你程序中有哪些错误。
2: 刚才我们选择的打开方式为D:\WinBinder\binaries\php51\ 下的.exe 文件,可能有朋友要问了,为什么不能选择本机中已经 安装好的php( 假设是D:/php) 文件夹下的.exe 文件呢?其实是可以的,但是这里有一个问题,如果选择php 文件夹下的.exe 文件,那么它使用 的是c:\windows 下的php.ini 配置文件,这样的话winbinder 运行时加载的.dll 文件,实际上是D:/php/ext/ 文件夹中的 文件。所以这个时候需要把php.ini 中的extension_dir 设置为./ext 因为ext 文件夹是和.exe 文件在同一文件夹中的( 即 D:\php 文件夹) 。然后还需要把D:\WinBinder\binaries\php51\ext 中的php_winbinder.dll 文件放到 D:\php\ext 中,然后相应的在c:\windows 下的php.ini 文件中加上extension=php_winbinder.dll 。另外 如果需要使用相应的库文件的话,需要在php.ini 中对应的文件名前的; 号去掉,这个我想大家都知道吧。
如果选择打开方式为D:\WinBinder\binaries\php51\ 下的.exe 文件则就没有这么麻烦,它使用的是D:\WinBinder \binaries\php51\ 下的php.ini 文件,你可以不作任何的配置就可以使用,但是他只默认支持mysql 和sqlite 这两个库,如果你 希望使用其他的库例如gd 那么就需要修改D:\WinBinder\binaries\php51\ 下的php.ini 文件,然后把对应的库文件( 例如 php_gd.dll) 放到D:\WinBinder\binaries\php51\ext 下。

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

没有优点
但http://www.gnope.org/download.php无法访问
还望楼主不吝赐解。
我觉得 PHP 似乎更适合做 Web 这类“无状态”通讯,因为请求结束可以回收所有资源。
PHP 虽然和 Python 一样使用引用计数器管理内存,但是之前一直没有特殊的 gc 方法处理引用计数器会引起泄漏的问题,例如引用自身的类。这方面 Python 明显比 PHP 强。而PHP没有跨请求解决方案和这也有很大关系。
这一点直到 5.3 分支才有所举措,不过我觉得是很难和 Python 比了吧。
这个应该只是其中的一个原因。
边角料只是浪费有限的生命而已
麻烦。。。用php作这个玩玩可以,真要用在产品上要走的路还很长,可能长到都走不下去
这个不是费劲不费劲的问题,如果一个只搞php的人,他根本不懂.net,也没必要再学习.net,还是用自己熟悉的东西更好
这个不是费劲不费劲的问题,如果一个只搞php的人,他根本不懂.net,也没必要再学习.net,还是用自己熟悉的东西更好
如果他只搞php开发web应用,的确没必要再学习.net,如果想开发windows客户端,我还是推荐他再学习.net,结果远比学习GTK类库的简单有效。这个当兴趣不错,用处的确鸡肋。